Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save aspose-com-gists/ffdbc5f1276884f783ffb953d50bfc5e to your computer and use it in GitHub Desktop.

Select an option

Save aspose-com-gists/ffdbc5f1276884f783ffb953d50bfc5e to your computer and use it in GitHub Desktop.
Resize EPS with Java

Resize EPS Examples

These code snippets show how to resize and crop EPS files using Aspose.Page for Java. The library enables precise manipulation of EPS page dimensions for publishing and printing workflows.

Key Use Cases

  • Get the original size and resize EPS to target width/height assigned in points
  • Obtain the exisiting size and resize EPS assigning new dimensions in inches
  • Get the original size and resize EPS with new width/height assigned in millimeters
  • Obtain the exisiting size and resize EPS assigning new dimensions in percents of original ones
  • Get the original bounding box and crop EPS to a region of interest

How to Run Examples

  1. Reference Aspose.Page for Java in your project.
  2. Copy the required code snippet into your project.
  3. Download a temporary license and set it up as described here or use a paid license.
  4. Run the example.

Restrictions

In evaluation mode, input EPS file is limited to 500Kb. Set up a valid temporary or paid license to use these features.

Related Documentation

See Resize and Crop EPS Files in the official documentation for more details.

Related Resources

Requirements

  • Java 8 or higher
  • Aspose.Page for Java library
Aspose.Page for Java – Resize nad Crop EPS Examples
// Cropping EPS file.
// Learn more: https://docs.aspose.com/page/java/crop-eps/
// Initialize PS document with EPS file
PsDocument document = new PsDocument(getDataDir() + "input.eps");
String outputFileName = "output_crop.eps";
//Get initial bounding box of EPS image
int[] initialBoundingBox = document.extractEpsBoundingBox();
//Create new bounding box
//Bounding box is represented by 4 numbers: x0, y0, x, y, where x0 - left margin, y0 - top margin, x - (x0 + width), y - (y0 + height)
float[] newBoundingBox = new float[] { 260, 300, 480, 432 };
//Crop EPS image and save to the output stream
//Croping of image is changing of its bounding box so that new values of bounding box will be within initial bounding box, that is
//initialBoundingBox[0] <= newBoundingBox[0] <= initialBoundingBox[2]
//initialBoundingBox[1] <= newBoundingBox[1] <= initialBoundingBox[3]
//initialBoundingBox[0] <= newBoundingBox[2] <= initialBoundingBox[2]
//initialBoundingBox[1] <= newBoundingBox[3] <= initialBoundingBox[3]
document.cropEps(getOutputDir() + outputFileName, newBoundingBox);
// Setting new size of EPS file in inches.
// Learn more: https://docs.aspose.com/page/java/resize-eps/#c-resize-eps-inches
// Initialize PS document with EPS file
PsDocument document = new PsDocument(getDataDir() + "input.eps");
String outputFileName = "output_resize_inches.eps";
//Get size of EPS image
Dimension oldSize = document.extractEpsSize();
//Save EPS file with new name and new size assigned in inches
document.resizeEps(getOutputDir() + outputFileName,
new DimensionF(5.791f, 3.625f), Units.Inches);
// Setting new size of EPS file in millimeters.
// Learn more: https://docs.aspose.com/page/java/resize-eps/#c-resize-eps-mms
// Initialize PS document with EPS file
PsDocument document = new PsDocument(getDataDir() + "input.eps");
String outputFileName = "output_resize_mms.eps";
//Get size of EPS image
Dimension oldSize = document.extractEpsSize();
//Save EPS file with new name and new size assigned in millimeters
document.resizeEps(getOutputDir() + outputFileName,
new DimensionF(196, 123), Units.Millimeters);
// Setting new size of EPS file in percents of original size.
// Learn more: https://docs.aspose.com/page/java/resize-eps/
// Initialize PS document with EPS file
PsDocument document = new PsDocument(getDataDir() + "input.eps");
String outputFileName = "output_resize_percents.eps";
//Get size of EPS image
Dimension oldSize = document.extractEpsSize();
//Save EPS file with new name and new size assigned in percents of original size
document.resizeEps(getOutputDir() + outputFileName,
new DimensionF(200, 200), Units.Percents);
// Setting new size of EPS file in points.
// Learn more: https://docs.aspose.com/page/java/resize-eps/#c-resize-eps-points
// Initialize PS document with EPS file
PsDocument document = new PsDocument(getDataDir() + "input.eps");
String outputFileName = "output_resize_points.eps";
//Get size of EPS image
Dimension oldSize = document.extractEpsSize();
//Increase EPS size in 2 times and save to new file
document.resizeEps(getOutputDir() + outputFileName,
new DimensionF(oldSize.width * 2, oldSize.height * 2), Units.Points);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment