Resize and crop EPS

Native API Solution for Java to manage size of EPS images

 

Unleash the power of our Java API Solution to effortlessly crop and resize EPS files. Our technology allows you to trim and enhance your visuals with precision, adjusting the margins to create the perfect image. The resulting EPS image is always more captivating, and the best part? Your file size remains unchanged.

Cropping an image is a precise operation that trims the image's margins – left, right, top, and bottom – removing excess content at the edges. This results in a more compact EPS image, always smaller than the original. Notably, our solution keeps the file size unchanged by focusing exclusively on the EPS file header, leaving your content intact. The EPS image's margins are determined by the BoundingBox metadata. To redefine these margins and establish a new bounding box, it's crucial to know the existing bounding box of the EPS image. This ensures error-free cropping and a flawless outcome.

To resize or crop EPS first get:

  • Aspose.Page for Java API which is a feature-rich, powerful, and easy-to-use document manipulation and conversion API for the Java platform.

  • You can download its latest version directly from Maven and install it within your Maven-based project by adding the following configurations to the pom.xml.

Package Manager Console Command


    <repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java API</name>
    <url>https://repository.aspose.com/repo/</url>
    </repository>

Dependency

    <dependency>
    <groupId>com.aspose</groupId>
    <artifactId>aspose-page</artifactId>
    <version>version of aspose-page API</version>
    <classifier>jdk17</classifier>
    </dependency>

Steps to cut EPS image Java.

The example below shows the getting rid of white margins from .eps with the chosen units - points. The order is:

  1. Initialize the PsDocument object with an input stream containing an EPS file.
  2. Define the existing bounding box of the image using the extractEpsBoundingBox() static method.
  3. Create an output stream for the resulting EPS file.
  4. Create a new bounding box.
  5. Cut off the needless borders of EPS file with a new bounding box using the cropEps() static method.
  6. Save the result file.

C# Code to crop EPS images.

    // Set the path to the documents directory.
    String dataDir = getDataDir();

    //Create an input stream for an EPS file
    FileInputStream inputEpsStream = new FileInputStream(dataDir + "input.eps");

    //Initialize the PsDocument object with input stream
    PsDocument doc = new PsDocument(inputEpsStream);

    //Get the initial bounding box of EPS image
    int [] initialBoundingBox = doc.extractEpsBoundingBox();

    //Create an output stream for the PostScript document
    FileOutputStream outputEpsStream = new FileOutputStream(dataDir + "output_crop.eps");

    //Create a 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 the EPS image and save to the output stream                   
    //Croping of the image is changing its bounding box so that the new values of the bounding box will be within the 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]
    doc.cropEps(outputEpsStream, newBoundingBox);



FAQ

1. Is it possible to change the size of EPS files?

EPS files are essentially PostScript files encapsulated within a bounding box, and they can be resized by modifying the bounding box parameters to specify the desired region of the image. This process effectively trims away any unwanted areas of the EPS image or make them bigger.

2. How can I resize an Encapsulated PostScript file?

Aspose.Page lets you set a new size for EPS files using the ExtractEpsSize() static Method to get the size of the actual file and resize it with a new size in points with the ResizeEps() static Method.

3. Are there any tools or software specifically designed for changing the size of EPS (Encapsulated PostScript) files?

Aspose.Page has EPS Resize cross-platform application that lets you resize files online in just a second.

EPS What is EPS File Format

EPS (EPSF) or Encapsulated PostScript File Format is the format that is actually a PS program that describes what would a single page look like. It is actually limited PS plus particular notes that help encapsulate PostScript graphics to another document. EPS perfectly supports vector graphics or combined vector-raster graphics. The peculiarity of the format is that as soon as it is imported into a document, it cannot be edited anymore. That is one of the reasons to convert this format to the one you are able to work with.