Convert EPS or PS PostScript File to an SVG Image using Java

Convert EPS PS to SVG

EPS or PS PostScript files are based on page description language that can contain different artifacts like Text, Images, Drawings, etc. You can convert an EPS or PS Postscript file to an SVG image (Scalable Vector Graphic) as per your requirements. Please refer to the following headings for more information:

EPS or PS PostScript File to SVG Image Converter – Java API Configuration

EPS or PS PostScript file to SVG image conversion is a two-step process. First, you need to convert the input EPS/PS file to a PDF document with Aspose.Page for Java. Then render the PDF file to an SVG image with Aspose.PDF for Java. Please download the JAR files from the New Releases section, or use the following configurations in the pom.xml file of your Maven-based project:

Repository

 <repositories>
     <repository>
         <id>snapshots</id>
         <name>repo</name>
         <url>http://repository.aspose.com/repo/</url>
     </repository>

</repositories>

Dependency

 <dependencies>
    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-page</artifactId>
        <version>21.8</version>
    </dependency>

    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-pdf</artifactId>
        <version>21.9</version>
    </dependency>

</dependencies>

Convert EPS or PS PostScript File to an SVG Image with Java

You can convert an EPS or PS PostScript File to an SVG image with the below steps:

  1. Initialize ByteArrayOutputStream to hold intermediary file.
  2. Initialize EPS or PS PostScript input stream.
  3. Declare PsDocument class object.
  4. Initialize PdfSaveOptions object with necessary parameters.
  5. Convert EPS or PS Postscript file to PDF with the save method.
  6. Load the PDF file and convert the EPS or PS PostScript file to an SVG file.

The following code shows how to convert an EPS or PS PostScript file to an SVG (Scalable Vector Graphic) image file with Java:

// Initialize ByteArrayOutputStream to hold intermediary PDF file.
final ByteArrayOutputStream pdfStream = new ByteArrayOutputStream();
// Initialize PsDocument with PostScript file.
PsDocument document = new PsDocument("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);
options.setJpegQualityLevel(50);
// 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"});
// Convert EPS or PS Postscript file to PDF stream
document.saveAsPdf(pdfStream , options);
// Load the intermediary PDF file
com.aspose.pdf.Document doc = new com.aspose.pdf.Document(pdfStream.toByteArray());
// Instantiate an object of SvgSaveOptions
com.aspose.pdf.SvgSaveOptions saveOptions = new com.aspose.pdf.SvgSaveOptions();
// Convert the EPS or PS file to an SVG file
doc.save("output.svg", saveOptions);
view raw EPS-to-SVG.java hosted with ❤ by GitHub

Get Free Evaluation License

There are some evaluation limitations for the APIs, which you can avoid by requesting a Free Temporary License and test the APIs in full capacity.

Conclusion

In this article, you have learned how to convert an EPS or PS PostScript file to an SVG image using Java. You have explored the simple and easy steps for the conversion. Moreover, please explore the Documentation for further information about the APIs, and feel free to contact us at the Free Support Forum to discuss any of your concerns.

See Also

Convert OXPS or XPS to PDF Programmatically with Java