이 간단한 자습서는 Java에서 OTG를 PDF로 변환하는 방법의 기본 사항을 설명합니다. MS Windows, Linux 또는 macOS와 같은 모든 운영 체제에서 몇 줄의 코드를 사용하여 자바에서 OTG를 PDF로 내보낼 수 있습니다. OTG에서 변환하기 전에 출력 PDF 파일에서 많은 옵션과 규정 준수 설정을 구성할 수 있습니다.
Java에서 OTG를 PDF로 변환하는 단계
- OTG를 PDF로 변환하려면 프로젝트의 Maven Repository에서 Aspose.Imaging를 설치하세요.
- 입력 OTG 파일을 Image 클래스 개체에 로드
- PdfOptions 클래스 개체를 초기화하여 출력 PDF의 속성을 설정합니다.
- PdfComplianceVersion 열거형을 사용하여 출력 PDF에 대한 규정 준수 설정 지정
- 출력 PDF 파일 해상도 및 메타데이터 정보 설정
- 입력 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로 변환하는 방법를 방문하여 이미지 작업을 위한 다양한 기능을 확인할 수 있습니다.