Convert PS, EPS, and XPS
PS, EPS, and XPS converter API Solution for Java
Whenever there is need to convert PostScript PS and Encapsulated PostScript EPS Files as well as XPS documents programatically, Java API can do it smoothly and converts multiples files. For PS and EPS, API supports Levels 1-3 PostScript operators and the most of the EPS header comments as well as transforms PostScript documents having maximum conformity with an exception of few fonts cases and API deals such fonts as Time New Roman.
Moreover, for XPS file transformation, API can add or remove pages, deals with canvases, paths, and glyph elements, create vector graphics shapes, and text strings, convert XPS outline items, and more.
The API solution for Java here lets you convert files of such PDL formats as PS, EPS, and XPS programmatically, but you may find useful to see and try cross-platform developed on these native APIs.
PostScript to PDF Conversion via Java.
To convert PostScript PS and Encapsulated PostScript EPS files to PDF via Java API you need to take the next steps:
- Load the PS or EPS file using the PsDocument class.
- Create a PdfSaveOptions object and set the conversion options you need.
- Call PsDocument.saveAsPdf() with the output file path and the options object.
Java Code to convert PS EPS to PDF
// 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());
}
}PostScript to Images Conversion via Java.
For any EPS/PS PostScript to image converter application, the following Java code works well, so take the next steps:
- Load the PS or EPS file using the PsDocument class.
- Create an ImageSaveOptions object for the target image format.
- Call PsDocument.saveAsImage() with the options object, the output folder and the file name.
Java Code for PostScript to Images Conversion
// 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());
}
}Convert XPS to Images JPG, PNG, BMP via Java.
Java API deals XPS format that is used for representing page layout. In any scenario, whenever there is a need to convert XPS to images BMP, JPG, PNG, and TIFF programmatically, the following code can easily be integrated within the Java application.
- Load the XPS document using the XpsDocument class.
- Create the save options class for the target format — PngSaveOptions , JpegSaveOptions , BmpSaveOptions or TiffSaveOptions .
- Call XpsDocument.saveAsImage() with the options object, the output folder and the file name.
Java Code for XPS to Image Conversion
// 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. Can I convert Postscript with this API solution?
Aspose.Page has functionality that allows you to convert PS, XPS, and EPS files to other formats online or programmatically. If you need to transform your files instantly online you may like to use Page Description Language format files Converter cross-platform application.
2. What Page description Languages are supported by the converter?
This conversion functionality supports files with .ps, .eps, and .xps extensions. Such famous PDLs as PDF and SVG are represented as separate solutions in Aspose.products
3. Is the functionality free?
The cross-platform converters are free, when for the API solution you can get a free Trial and then buy the product if needed.
Convert XPS to PDF via Java.
The process of converting XPS to PDF documents programmatically is simple having high fidelity results among the input and output files.
- Load the XPS file using the XpsDocument class.
- Create a PdfSaveOptions object.
- Call XpsDocument.saveAsPdf() with the output file path and the options object.
Java Code for XPS to PDF Conversion
// 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);Support and Learning Resources
- Learning Resources
- Documentation
- Source Code
- API References
- Product Support
- Free Support
- Paid Support
- Blog
- Release Notes
- Why Aspose.Page for Java?
- Customers List
- Success Stories