Convert EPS to TIFF using Java
You can check the quality of Aspose.Page EPS to TIFF conversion and view the results via free online EPS to TIFF Converter or EPS Viewer
Aspose.Page for Java EPS to TIFF converter allows to convert Encapsulated PostScript (EPS) file to TIFF image on any OS for which Java Virtual Machine exists.
It is necessary to do several steps in order to perform EPS to TIFF conversion:
- Initialize an input stream for input EPS file.
- Create an instance of PsDocument from created earlier input stream.
- Use ImageSaveOptions to specify AdditionalFontsFolder and SuppressError boolean value.
- Create an instance of ImageDevice specifying image type and size if it is necessary.
- Save PostScript document as image with image save options to an array of arrays of bytes. One array of bytes for one page of input document.
- Save resulting 2-dimensional arrays of bytes to TIFF files creating for every bytes array a new file output stream.
- If SuppressErrors value was true, as it is by default, It is possible to see what errors were thrown during conversion of EPS to TIFF.
Following code snippet shows how to convert EPS to TIFF files in Java:
1// For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-Java
2// The path to the documents directory.
3String dataDir = Utils.getDataDir();
4//Initialize image format
5ImageFormat imageFormat = ImageFormat.TIFF;
6// Initialize Encapsulated PostScript input stream
7FileInputStream psStream = new FileInputStream(dataDir + "input.eps");
8
9PsDocument document = new PsDocument(psStream);
10
11// If you want to convert Postscript file despite of minor errors set this flag
12boolean suppressErrors = true;
13
14//Initialize options object with necessary parameters.
15ImageSaveOptions options = new ImageSaveOptions(suppressErrors);
16// If you want to add special folder where fonts are stored. Default fonts folder in OS is always included.
17//options.setAdditionalFontsFolders(new String [] {"FONTS_FOLDER"});
18
19// Default image size is 595x842 and it is not mandatory to set it in ImageDevice
20com.aspose.eps.device.ImageDevice device = new com.aspose.eps.device.ImageDevice(imageFormat);
21// But if you need to specify size use constructor with two parameters
22//ImageDevice device = new ImageDevice(new Dimension(595, 842), imageFormat);
23
24try {
25 document.save(device, options);
26} finally {
27 psStream.close();
28}
29
30byte[][] imagesBytes = device.getImagesBytes();
31
32int i = 0;
33
34for (byte [] imageBytes : imagesBytes) {
35 String imagePath = dataDir + "EPSToImage" + i + "." + imageFormat.toString().toLowerCase();
36 FileOutputStream fs = new FileOutputStream(imagePath);
37
38 try {
39 fs.write(imageBytes, 0, imageBytes.length);
40 } catch (IOException ex) {
41 System.out.println(ex.getMessage());
42 } finally {
43 fs.close();
44 }
45 i++;
46}
47
48//Review errors
49if (suppressErrors) {
50 for (Exception ex : options.getExceptions()) {
51 System.out.println(ex.getMessage());
52 }
53}
Let’s consider
ImageSaveOptions. Using this class we can assign different conversion parameters while converting EPS to TIFF.
- AdditionalFontsFolder specifies locations where to find fonts. System fonts folders are always included by default.
- SuppressError controls behaviour of EPS to TIFF converter when non-critical errors are appeared. If value is true than it is possible to view a list of such errors after conversion in Exceptions field. Default value is true.
- Debug allows outputting debug information to console. Default value is false.
Evaluate EPS to TIFF conversion online on our EPS to TIFF Converter. You can convert several EPS files to TIFF at once and dowload results in a few seconds.
You can download examples and data files from
GitHub.