PS, EPS 및 XPS 변환
Java용 PS, EPS 및 XPS 변환기 API 솔루션
PostScript PS 및 Encapsulated PostScript EPS 파일은 물론 XPS 문서를 프로그래밍 방식으로 변환해야 할 때마다 Java API는 이를 원활하게 수행하고 여러 파일을 변환할 수 있습니다. PS 및 EPS의 경우 API는 레벨 1-3 PostScript 연산자와 대부분의 EPS 헤더 주석을 지원하며, 몇 가지 글꼴 사례를 제외하고는 최대한의 적합성을 갖춘 PostScript 문서를 변환합니다. API는 이러한 글꼴을 Time New Roman처럼 처리합니다.
또한 XPS 파일 변환의 경우 API는 페이지를 추가하거나 제거하고, 캔버스, 경로 및 글리프 요소를 처리하고, 벡터 그래픽 모양과 텍스트 문자열을 만들고, XPS 아웃라인 항목을 변환하는 등의 작업을 수행할 수 있습니다.
여기에 있는 Java용 API 솔루션을 사용하면 PS, EPS 및 XPS와 같은 PDL 형식의 파일을 프로그래밍 방식으로 변환할 수 있지만, 이러한 네이티브 API를 기반으로 개발된 크로스 플랫폼 도구를 보고 시도해 보는 것도 유용할 수 있습니다.
Java를 통한 PostScript에서 PDF로의 변환.
Java API를 통해 PostScript PS 및 Encapsulated PostScript EPS 파일을 PDF로 변환하려면 다음 단계를 수행해야 합니다.
- PsDocument 클래스를 사용하여 PS 또는 EPS 파일을 로드합니다.
- PdfSaveOptions 개체를 만들고 필요한 변환 옵션을 설정합니다.
- 출력 파일 경로와 옵션 개체를 사용하여 *PsDocument.saveAsPdf()*을(를) 호출합니다.
PS EPS를 PDF로 변환하는 Java 코드
// Convert PS file to PDF document.
// Learn more: https://docs.aspose.com/page/java/convert-ps/
// Initialize PsDocument with the name of PostScript file.
PsDocument document = new PsDocument(getDataDir() + "input.ps");
// If you want to convert Postscript file despite of minor errors set this flag
boolean suppressErrors = true;
//Initialize options object with necessary parameters.
PdfSaveOptions options = new PdfSaveOptions(suppressErrors);
// If you want to add special folder where fonts are stored. Default fonts folder in OS is always included.
options.setAdditionalFontsFolders(new String[] { "{FONT_FOLDER}" });
// Default page size is 595x842 and it is not mandatory to set it in PdfSaveOptions
// But if you need to specify sizeuse following line
//PdfSaveOptions options = new PdfSaveOptions(suppressErrorsnew, java.awt.Dimension(595x842));
// or
//saveOptions.setSize(new java.awt.Dimension(595x842));
//If PostScript file contains some graphics written as Type3 font glyphs, but it is not actual glyphs
//the resulting PDF may be incorrect because of default value of options.ConvertFontsToTTF = true
//Try to set this
//options.setConvertFontsToTTF(false);
// Save document as PDF
document.saveAsPdf(getOutputDir() + "outputPDF_out.pdf", options);
//Review errors
if (suppressErrors) {
for (Exception ex : options.getExceptions()) {
System.out.println(ex.getMessage());
}
}Java를 통한 PostScript에서 이미지로의 변환.
모든 EPS/PS PostScript 이미지 변환기 응용 프로그램의 경우 다음 Java 코드가 잘 작동하므로 다음 단계를 수행하십시오.
- PsDocument 클래스를 사용하여 PS 또는 EPS 파일을 로드합니다.
- 대상 이미지 형식에 맞는 ImageSaveOptions 개체를 만듭니다.
- 옵션 개체, 출력 폴더, 파일 이름을 사용하여 *PsDocument.saveAsImage()*을(를) 호출합니다.
PostScript에서 이미지로의 변환을 위한 Java 코드
// Convert PS file to PNG image.
// Learn more: https://docs.aspose.com/page/java/convert-ps/
//Outut file
String outputFileName = "output_image.png";
// Initialize PsDocument with the name of PostScript file.
PsDocument document = new PsDocument(getDataDir() + "inputForImage.ps");
// If you want to convert Postscript file despite of minor errors set this flag
boolean suppressErrors = true;
//Initialize options object with necessary parameters.
ImageSaveOptions options = new ImageSaveOptions();
//Set output image format.
options.setImageFormat(ImageFormat.PNG);
// If you want to add special folder where fonts are stored. Default fonts folder in OS is always included.
options.setAdditionalFontsFolders(new String[] { "{FONT_FOLDER}" });
// Save PS document to an image.
document.saveAsImage(options, getOutputDir(), getFileNameWithoutExtension(outputFileName));
//Review errors
if (suppressErrors) {
for (Exception ex : options.getExceptions()) {
System.out.println(ex.getMessage());
}
}Java를 통해 XPS를 이미지 JPG, PNG, BMP로 변환합니다.
Java API는 페이지 레이아웃을 나타내는 데 사용되는 XPS 형식을 처리합니다. 어떤 시나리오에서든 XPS를 이미지 BMP, JPG, PNG 및 TIFF로 프로그래밍 방식으로 변환해야 할 때마다 다음 코드를 Java 응용 프로그램 내에 쉽게 통합할 수 있습니다.
- XpsDocument 클래스를 사용하여 XPS 문서를 로드합니다.
- 대상 형식에 맞는 저장 옵션 클래스( PngSaveOptions , JpegSaveOptions , BmpSaveOptions 또는 TiffSaveOptions )를 만듭니다.
- 옵션 개체, 출력 폴더, 파일 이름을 사용하여 *XpsDocument.saveAsImage()*을(를) 호출합니다.
XPS에서 이미지로의 변환을 위한 Java 코드
// Convert XPS file to PNG image.
// Learn more: https://docs.aspose.com/page/java/convert-xps/
//Outut file
String outputFileName = "XPStoPNG_out.png";
// Load XPS document form the XPS file
XpsDocument document = new XpsDocument(getDataDir() + "input.xps");
// Initialize options object with necessary parameters.
PngSaveOptions options = new PngSaveOptions();
options.setSmoothingMode(SmoothingMode.HighQuality);
options.setResolution(300);
options.setPageNumbers(new int[] { 1, 2, 6 });
// Save XPS document to the PNG image files.
document.saveAsImage(options, getOutputDir(), outputFileName);FAQ
1. 이 API 솔루션으로 Postscript를 변환할 수 있습니까?
Aspose.Page에는 온라인 또는 프로그래밍 방식으로 PS, XPS 및 EPS 파일을 다른 형식으로 변환할 수 있는 기능이 있습니다. 파일을 온라인에서 즉시 변환해야 하는 경우 페이지 설명 언어 형식 파일 변환기 크로스 플랫폼 응용 프로그램을 사용하는 것이 좋습니다.
2. 변환기에서 지원하는 페이지 설명 언어는 무엇입니까?
이 변환 기능은 확장자가 .ps, .eps 및 .xps인 파일을 지원합니다. PDF 및 SVG와 같은 유명한 PDL은 Aspose.products에서 별도의 솔루션으로 표시됩니다.
3. 기능은 무료인가요?
크로스 플랫폼 변환기 는 무료입니다. API 솔루션의 경우 무료 평가판을 받은 다음 필요한 경우 제품을 구매할 수 있습니다.
Java를 통해 XPS를 PDF로 변환합니다.
XPS를 PDF 문서로 프로그래밍 방식으로 변환하는 프로세스는 간단하며 입력 파일과 출력 파일 간에 높은 충실도의 결과를 얻을 수 있습니다.
- XpsDocument 클래스를 사용하여 XPS 파일을 로드합니다.
- PdfSaveOptions 개체를 만듭니다.
- 출력 파일 경로와 옵션 개체를 사용하여 *XpsDocument.saveAsPdf()*을(를) 호출합니다.
XPS에서 PDF로의 변환을 위한 Java 코드
// Convert XPS file to PDF document.
// Learn more: https://docs.aspose.com/page/java/convert-xps/
// Load XPS document form the XPS file
XpsDocument document = new XpsDocument(getDataDir() + "input.xps");
// Initialize options object with necessary parameters.
PdfSaveOptions options = new PdfSaveOptions();
options.setJpegQualityLevel(100);
options.setImageCompression(PdfImageCompression.Jpeg);
options.setTextCompression(PdfTextCompression.Flate);
options.setPageNumbers(new int[] { 1, 2, 6 });
// Save document as PDF
document.saveAsPdf(getOutputDir() + "XPStoPDF_out.pdf", options);