JavaでOTGをPDFに変換する方法

この簡単なチュートリアルでは、JavaでOTGをPDFに変換する方法の基本について説明します。これにより、MS Windows、Linux、macOSなどのオペレーティングシステムで数行のコードを使用して、JavaでOTGPDFにエクスポートできるようになります。オプションとコンプライアンス設定の多くは、OTGから変換する前に出力PDFファイルで構成できます。

JavaでOTGをPDFに変換する手順

  1. プロジェクトのMavenリポジトリからAspose.Imagingをインストールして、OTGをPDFに変換します
  2. 入力OTGファイルをImageクラスオブジェクトにロードします
  3. PdfOptionsクラスオブジェクトを初期化して、出力PDFのプロパティを設定します
  4. PdfComplianceVersion列挙型を使用して出力PDFのコンプライアンス設定を設定します
  5. 出力PDFファイルの解像度とメタデータ情報を設定します
  6. 入力OTGファイルから変換された出力PDFファイルを保存します

上記の手順では、ソースOTGファイルをロードし、出力PDFファイルのプロパティを設定するためにPdfOptionsクラスインスタンスを初期化しました。 * JavaでOTGをPDFに変更する*このプロセスでは、出力ファイルの水平および垂直解像度とメタデータを含むいくつかのプロパティを設定しましたが、他の多くのプロパティも設定できます。

JavaでOTGをPDFにエクスポートするコード

import com.aspose.imaging.License;
import com.aspose.imaging.ResolutionSetting;
import com.aspose.imaging.fileformats.pdf.PdfDocumentInfo;
import com.aspose.imaging.imageoptions.PdfOptions;
import com.aspose.imaging.Image;
public class ConvertOTGToPDFInJava {
public static void main(String[] args) {//main function for the ConvertOTGToPDFInJava class
// Set the Aspose.Imaging license to avoid trial version message in the output PDF file exported from OTG
License ImagingLicense = new License();
ImagingLicense.setLicense("Aspose.Imaging.lic");
// Load the input OTG sample file to be converted to a PDF file into an Image object
Image InputOTGFile = Image.load("Input_OTG.otg");
// Instantiate a PdfOptions class instance to set properties for the output PDF
PdfOptions PDFOptionsForOutputFile = new PdfOptions();
// Set the resolution settings of the output PDF file to 72 DPI
PDFOptionsForOutputFile.setResolutionSettings(new ResolutionSetting(72, 72));
// Specify the metadata information of the output PDF file like Author, Keywords, and Subject
PdfDocumentInfo PDFDocInfo = new PdfDocumentInfo();
PDFDocInfo.setAuthor("Document Author Information");
PDFDocInfo.setKeywords("Change OTG to PDF, OTG to PDF");
PDFDocInfo.setSubject("Export OTG to PDF in Java");
// Set the PDF document information for metadata
PDFOptionsForOutputFile.setPdfDocumentInfo(PDFDocInfo);
// Call the save function to generate output PDF file exported from the OTG
InputOTGFile.save("PDFConvertedFromOTG.pdf", PDFOptionsForOutputFile);
}
}

このコードサンプルでは、出力PDFファイルの水平および垂直解像度とメタデータ情報を構成してから、OTGをJavaでPDFにエクスポートします。要件に応じて、解像度、コンプライアンス、メタデータの値を変更できます。

さらに、JavaでBMPをPNGに変換する方法にアクセスして、画像を操作するためのさまざまな機能を確認できます。

 日本語