Last active
March 4, 2019 13:13
-
-
Save aspose-com-gists/a69759871f501395334013206e9c5eb4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Gists for Aspose.EPS for Java |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // For complete examples and data files, please go to https://github.com/aspose-eps/Aspose.EPS-for-Java | |
| // The path to the documents directory. | |
| String dataDir = Utils.getDataDir(); | |
| // Initialize PostScript input stream | |
| FileInputStream psStream = new FileInputStream( 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. Default image format is PNG and it is not required to set it in Ps2ApsConverterOptions. | |
| ImageFormat imageFormat = ImageFormat.PNG; | |
| Ps2ApsConverterOptions options = new Ps2ApsConverterOptions(psStream, suppressErrors); | |
| //If you want to obtain images in another format, uncomment following lines | |
| //imageFormat = com.aspose.eps.ImageFormat.Jpeg; | |
| //options = new Ps2ApsConverterOptions(psStream, suppressErrors, imageFormat); | |
| // Set page size. This size will be also the size of resulting images. | |
| options.setPageSize(new Dimension(595, 842)); | |
| // If you want to add special folder where fonts are stored. Default fonts folder in OS is always included. | |
| //options.setFontsFolders(new String[] { "{FONT_FOLDER}" }); | |
| Ps2ApsConverter converter = new Ps2ApsConverter(); | |
| try | |
| { | |
| //Because PS file can contain several pages for every page an image bytes array will be obtained. //The number of bytes arrays equals to the number of pages in input PS file. | |
| byte [][] imagesBytes = converter.convertToImages(options); | |
| int i = 0; | |
| for (byte [] imageBytes : imagesBytes) | |
| { | |
| String imagePath = "out_image" + i + "." + imageFormat.toString().toLowerCase(); | |
| FileOutputStream fs = new FileOutputStream(dataDir + imagePath); | |
| fs.write(imageBytes, 0, imageBytes.length); | |
| i++; | |
| } | |
| } | |
| finally | |
| { | |
| psStream.close(); | |
| } | |
| //Review errors | |
| if (suppressErrors) | |
| { | |
| for (PsConverterException ex : options.getExceptions()) { | |
| System.out.println(ex.getMessage()); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // For complete examples and data files, please go to https://github.com/aspose-eps/Aspose.EPS-for-Java | |
| // The path to the documents directory. | |
| String dataDir = Utils.getDataDir(); | |
| // Initialize PostScript input stream | |
| FileInputStream psStream = new FileInputStream( dataDir + "input.ps"); | |
| // Initialize PDF output stream | |
| FileOutputStream pdfStream = new FileOutputStream( dataDir + "EPStoPDF_out.pdf"); | |
| // If you want to convert Postscript file despite of minor errors set this flag | |
| Boolean suppressErrors = true; | |
| Ps2PdfConverterOptions options = new Ps2PdfConverterOptions(psStream, pdfStream, suppressErrors); | |
| // Set page size | |
| options.setPageSize(new Dimension(595, 842)); | |
| // If you want to add special folder where fonts are stored. Default fonts folder in OS is always included. | |
| //options.setFontsFolders(new String[] { "{FONT_FOLDER}" }); | |
| try | |
| { | |
| Ps2PdfConverter converter = new Ps2PdfConverter(); | |
| converter.convertToPdf(options); | |
| } | |
| finally | |
| { | |
| psStream.close(); | |
| pdfStream.close(); | |
| } | |
| //Review errors | |
| if (suppressErrors) | |
| { | |
| for (PsConverterException ex : options.getExceptions()) { | |
| System.out.println(ex.getMessage()); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment