Cara Mengonversi OTG ke PDF di Java

Tutorial singkat ini menjelaskan dasar-dasar cara mengonversi OTG ke PDF di Java. Ini akan memungkinkan Anda untuk mengekspor OTG ke PDF di Java dengan menggunakan beberapa baris kode pada sistem operasi apa pun seperti MS Windows, Linux, atau macOS. Banyak opsi dan pengaturan kepatuhan dapat dikonfigurasi dalam file PDF keluaran sebelum konversi dari OTG.

Langkah-langkah untuk Mengonversi OTG ke PDF di Java

  1. Instal Aspose.Imaging dari Repositori Maven di proyek Anda untuk mengonversi OTG ke PDF
  2. Muat file OTG masukan ke dalam objek kelas Image
  3. Inisialisasi objek kelas PdfOptions untuk mengatur properti untuk PDF keluaran
  4. Setel pengaturan kepatuhan untuk PDF keluaran dengan enum PdfComplianceVersion
  5. Atur resolusi file PDF keluaran dan informasi metadata
  6. Simpan file PDF keluaran yang dikonversi dari file OTG input

Pada langkah di atas, kami telah memuat file OTG sumber dan menginisialisasi instance kelas PdfOptions untuk mengatur properti file PDF keluaran. Dalam proses ini untuk mengubah OTG ke PDF di Java kami telah mengatur beberapa properti termasuk resolusi horizontal dan vertikal dan metadata dari file output namun banyak properti lainnya juga dapat diatur.

Kode untuk Mengekspor OTG ke PDF di Java

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);
}
}

Dalam contoh kode ini, resolusi horizontal dan vertikal serta informasi metadata dari file PDF keluaran dikonfigurasi sebelum mengekspor OTG ke PDF di Java. Anda dapat mengubah nilai resolusi, kepatuhan, dan metadata sesuai kebutuhan Anda.

Selanjutnya, Anda dapat mengunjungi cara mengonversi BMP ke PNG di Jawa untuk memeriksa berbagai fitur untuk bekerja dengan gambar.

 Indonesian