Resize EPS using Java API Solution
Overview
This article explains how to resize EPS using Java. It covers the following topics.
- Java Resize EPS Description
- Java Resize EPS setting new size in Points
- Java Resize EPS setting new size in Inches
- Java Resize EPS setting new size in Millimeters
- Java Resize EPS setting new size in Percents
Java Resize EPS Description
Resizing the image is an operation that changes one of the, or both, dimensions of the image: width and height. The content of the image is left the same, but the image itself can be scaled in dependence of new values of width and height. If with and height are proportionally increased the representation of EPS image will be enlarged, otherwise it will be lessened. If width and height are changed disproportionately the resulting representation of EPS image will be compressed or elangated in some direction. The volume of the EPS file will remain almost unchanged as our solution doesnt’t work with the content but works with the header and the setup section of EPS file. To set up new size for the representation of EPS image often it is necessary to know its existing size and choise the units in which to assign new size. It can be Points (1/72 of inch), Inches, Millimeters, Centimeters and Percents. So the steps for resizing EPS image in Java follows:
- Initialize PsDocument object with an input stream containing EPS file.
- Extract existing size of the image using static method extractEpsSize.
- Create an output stream for resulting EPS file.
- Resize PsDocument object with new size in selected Units with static method resizeEps.
You can check the quality of Aspose.Page EPS Resize and view the results via free online Resize EPS and than view the resulting EPS file with our EPS Viewer
Resize EPS setting new size in Points in Java
In the following Java code snippet new size of the image is set by Points (1/72 of inch):
1// For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-Java
2
3// The path to the documents directory.
4String dataDir = getDataDir();
5
6//Create an input stream for EPS file
7FileInputStream inputEpsStream = new FileInputStream(dataDir + "input.eps");
8
9//Initialize PsDocument object with input stream
10PsDocument doc = new PsDocument(inputEpsStream);
11
12//Get size of EPS image
13Dimension oldSize = doc.extractEpsSize();
14
15//Create output stream for PostScript document
16FileOutputStream outputEpsStream = new FileOutputStream(dataDir + "output_resize_points.eps");
17
18//Increase EPS size in 2 times and save to the output stream
19doc.resizeEps(outputEpsStream, new DimensionF(oldSize.width * 2, oldSize.height * 2), Units.Points);
Resize EPS setting new size in Inches in Java
In the following Java code snippet new size of the image is set by Inches:
1// For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-Java
2
3// The path to the documents directory.
4String dataDir = getDataDir();
5
6//Create an input stream for EPS file
7FileInputStream inputEpsStream = new FileInputStream(dataDir + "input.eps");
8
9//Initialize PsDocument object with input stream
10PsDocument doc = new PsDocument(inputEpsStream);
11
12//Get size of EPS image
13//Dimension oldSize = doc.extractEpsSize();
14
15//Create output stream for PostScript document
16FileOutputStream outputEpsStream = new FileOutputStream(dataDir + "output_resize_inches.eps");
17
18//Save EPS to the output stream with new size assigned in inches
19doc.resizeEps(outputEpsStream, new DimensionF(5.791f, 3.625f), Units.Inches);
Resize EPS setting new size in Millimeters in Java
In the following Java code snippet new size of the image is set by Millimeters:
1// For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-Java
2
3// The path to the documents directory.
4String dataDir = getDataDir();
5
6//Create an input stream for EPS file
7FileInputStream inputEpsStream = new FileInputStream(dataDir + "input.eps");
8
9//Initialize PsDocument object with input stream
10PsDocument doc = new PsDocument(inputEpsStream);
11
12//Create output stream for PostScript document
13FileOutputStream outputEpsStream = new FileOutputStream(dataDir + "output_resize_mms.eps");
14
15//Save EPS to the output stream with new size assigned in millimeters
16doc.resizeEps(outputEpsStream, new DimensionF(196, 123), Units.Millimeters);
Resize EPS setting new size in Percents in Java
In the following Java code snippet new size of the image is set by Percents:
1// For complete examples and data files, please go to https://github.com/aspose-page/Aspose.Page-for-Java
2
3// The path to the documents directory.
4String dataDir = getDataDir();
5
6//Create an input stream for EPS file
7FileInputStream inputEpsStream = new FileInputStream(dataDir + "input.eps");
8
9//Initialize PsDocument object with input stream
10PsDocument doc = new PsDocument(inputEpsStream);
11
12//Create output stream for PostScript document
13FileOutputStream outputEpsStream = new FileOutputStream(dataDir + "output_resize_percents.eps");
14
15//Save EPS to the output stream with new size assigned in percents
16doc.resizeEps(outputEpsStream, new DimensionF(200, 200), Units.Percents);
Initial image
Resized image
Evaluate resizing EPS online on our Resize EPS web application. You can resize EPS file and dowload result in a few seconds.
You can download examples and data files from
GitHub.