Last active
October 27, 2025 18:11
-
-
Save aspose-com-gists/acb980dffa67aef47bb0bd8fa8412264 to your computer and use it in GitHub Desktop.
Crop EPS Image in 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
| package com.example; | |
| import java.io.FileInputStream; | |
| import java.io.FileOutputStream; | |
| import java.io.IOException; | |
| import com.aspose.eps.PsDocument; | |
| import com.aspose.page.License; | |
| public class main { | |
| public static void main(String[] args) throws IOException { | |
| try { | |
| // Define the path for working directory and load the Aspose.Page license. | |
| String dataDir = "source"; | |
| License lic = new License(); | |
| lic.setLicense(dataDir + "license.lic"); | |
| // Create an input stream for the source EPS file. | |
| FileInputStream inputEpsStream = new FileInputStream(dataDir + "input.eps"); | |
| // Initialize PsDocument object with input stream. | |
| PsDocument doc = new PsDocument(inputEpsStream); | |
| // Create output stream for the output PostScript document. | |
| FileOutputStream outputEpsStream = new FileOutputStream(dataDir + "output_crop.eps"); | |
| // Create new bounding box which 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 }; | |
| // Finally, invoke the cropEps function to save the cropped EPS file. | |
| doc.cropEps(outputEpsStream, newBoundingBox); | |
| } catch (Exception e) { | |
| e.printStackTrace(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment