Learn how to convert EPS to PNG in Java : https://blog.aspose.com/2022/08/05/convert-eps-to-png-in-java/
The following topics are covered in this article:
Learn how to convert EPS to PNG in Java : https://blog.aspose.com/2022/08/05/convert-eps-to-png-in-java/
The following topics are covered in this article:
// This code example demonstrates how to convert EPS to PNG. | |
// Load file in input stream | |
FileInputStream psStream = new FileInputStream("C:\\Files\\input.eps"); | |
// Instantiate PS document | |
PsDocument document = new PsDocument(psStream); | |
// 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); | |
// Optionally, 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"}); | |
// Initialize image format as PNG | |
ImageFormat imageFormat = ImageFormat.PNG; | |
// Default image format is PNG and it is not mandatory to set it in ImageDevice | |
// Default image size is 595x842 and it is not mandatory to set it in ImageDevice | |
com.aspose.eps.device.ImageDevice device = new com.aspose.eps.device.ImageDevice(); | |
// But if you need to specify size and image format use constructor with parameters | |
//ImageDevice device = new ImageDevice(new Dimension(595, 842), com.aspose.eps.ImageFormat.Jpeg); | |
try { | |
// Save to device | |
document.save(device, options); | |
} finally { | |
psStream.close(); | |
} | |
// Get image bytes | |
byte[][] imagesBytes = device.getImagesBytes(); | |
int i = 0; | |
// Save to disk | |
for (byte [] imageBytes : imagesBytes) { | |
String imagePath = "C:\\Files\\PSToImage" + i + "." + imageFormat.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++; | |
} |