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 클래스 를 사용하여 PDF 저장 옵션을 설정합니다.
- 출력 PDF 파일에 FileStream 클래스 를 사용합니다.
- FileOutputStream 개체를 매개 변수로 갖는 PdfDevice 클래스 를 사용합니다.
- PsDocument.Save 를 호출하여 파일을 PDF로 저장합니다.
PS EPS를 PDF로 변환하는 Java 코드
// The path to the documents directory.
String dataDir = Utils.getDataDir();
// Initialize PS document with PostScript file
PsDocument document = new PsDocument(dataDir + "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);
// Default page size is 595x842 and it is not mandatory to set it in PdfDevice
// But if you need to specify size and image format use following line
// PdfSaveOptions options = new PdfSaveOptions(suppressErrors, new Dimension(595, 842));
// If you want to add special folder where fonts are stored. Default fonts folder in OS is always included.
//options.setAdditionalFontsFolders(new String [] {"FONTS_FOLDER"});
// Save PS document to PDF file
document.saveAsPdf(dataDir + "PStoPDF.pdf", options);
//Review errors
if (suppressErrors) {
for (Exception ex : pdfOptions.getExceptions()) {
System.out.println(ex.getMessage());
}
}Java를 통한 PostScript에서 이미지로의 변환.
모든 EPS/PS PostScript 이미지 변환기 응용 프로그램의 경우 다음 Java 코드가 잘 작동하므로 다음 단계를 수행하십시오.
- PS 소스 파일로 입력 스트림을 초기화합니다.
- 생성된 PS 입력 스트림을 매개 변수로 사용하여 PsDocument 개체를 만듭니다.
- ImageSaveOptions 를 사용하여 AdditionalFontsFolder 및 SuppressError 등을 지정합니다.
- ImageDevice 개체를 사용하여 필요한 경우 이미지 유형과 크기를 지정합니다.
- PS/EPS 파일을 바이트 배열의 배열인 이미지 저장 옵션을 사용하여 이미지로 저장합니다. 입력 파일의 한 페이지당 하나의 바이트 배열이 생성됩니다.
PostScript에서 이미지로의 변환을 위한 Java 코드
// The path to the documents directory.
String dataDir = Utils.getDataDir();
// Initialize PS document with PostScript file
PsDocument document = new PsDocument(dataDir + "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.
ImageSaveOptions options = new ImageSaveOptions(suppressErrors);
// Default image format is PNG and it is not mandatory to set it in ImageSaveOptions.
// But if you need to specify another format use following line
// options.setImageFormat(ImageFormat.JPEG);
// Default image size is 595x842 and it is not mandatory to set it in ImageDevice
// But if you need to specify size and image format use constructor with parameters
// ImageSaveOptions options = new ImageSaveOptions(new Dimension(595, 842), ImageFormat.JPEG, suppressErrors);
// If you want to add special folder where fonts are stored. Default fonts folder in OS is always included.
// options.setAdditionalFontsFolders(new String [] {"FONTS_FOLDER"});
// Save PS document as images bytes arrays, one bytes array for one page of the document.
byte[][] imagesBytes = document.saveAsImage(options);
int i = 0;
for (byte [] imageBytes : imagesBytes) {
String imagePath = dataDir + "PSToImage" + i + "." + options.getImageFormat().toString().toLowerCase();
FileOutputStream fs = new FileOutputStream(imagePath);
try {
fs.write(imageBytes, 0, imageBytes.length);
} catch (IOException ex) {
System.out.println(ex.getMessage());
} finally {
fs.close();
}
i++;
}
//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 와 같은 관련 이미지 옵션 클래스를 사용합니다.
- image device 클래스 인스턴스를 만듭니다.
- XpsDocument.save 를 호출하여 변환된 JPEG 이미지를 ImageDevice 개체에 저장한 다음 ImageDevice를 사용하여 이미지를 JPG로 저장합니다.
XPS에서 이미지로의 변환을 위한 Java 코드
// The path to the documents directory.
String pathDir = Utils.getDataDir();
// Load XPS document
XpsDocument document = new XpsDocument(dataDir + "input.xps");
// Initialize options object with necessary parameters.
com.aspose.xps.rendering.PngSaveOptions options = new com.aspose.xps.rendering.PngSaveOptions();
options.setSmoothingMode(com.aspose.xps.rendering.SmoothingMode.HighQuality);
options.setResolution(300);
options.setPageNumbers(new int[] { 1, 2, 6 });
// Save XPS document as images bytes array. One bytes array for one page of every parttion in the document
byte [][][] imagesBytes = document.saveAsImage(options);
// Iterate through document partitions (fixed documents, in XPS terms)
for (int i = 0; i < imagesBytes.length; i++) {
// Iterate through partition pages
for (int j = 0; j < imagesBytes[i].length; j++) {
// Initialize image output stream
FileOutputStream imageStream = new FileOutputStream(dataDir + "XPStoPNG" + "_" + (i + 1) + "_" + (j + 1) + ".png");
// Write image
imageStream.write(imagesBytes[i][j], 0, imagesBytes[i][j].length);
imageStream.close();
}
}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 클래스를 사용하여 파일을 로드합니다. PdfSaveOptions 클래스 개체를 초기화합니다.
- 렌더링을 위한 PdfDevice 개체를 생성하고 마지막으로 출력 PDF 문서를 저장합니다.
XPS에서 PDF로의 변환을 위한 Java 코드
// Load input XPS document
XpsDocument document = new XpsDocument(dataDir + "input.xps");
// Initialize options object with necessary parameters
PdfSaveOptions options = new PdfSaveOptions();
options.setJpegQualityLevel(100);
options.setImageCompression(PdfImageCompression.Jpeg);
options.setTextCompression(PdfTextCompression.Flate);
// Save XPS document to output PDF file
document.saveAsPdf(dataDir + "XPStoPDF.pdf", options);