Crop EPS | Node.js API Solution
Overview
This article explains how to crop EPS using Node.js. It covers the following topics.
Node.js Crop EPS Description
Cropping an image means adjusting its margins (left, right, top, or bottom), effectively trimming content from the edges.
When an EPS image is cropped with our solution, its visual size will always be smaller than the original. However, the file’s overall size won’t change. This is because our tool modifies the EPS file’s header (where metadata like the BoundingBox is stored), rather than altering the actual image content.
The margins of an EPS image are defined by its BoundingBox metadata. To successfully crop an image, or, in other words, to set a new bounding box, you must know the existing bounding box values. Attempting to define a new bounding box outside the current one will lead to an error.
So the steps for cropping EPS image in Node.js follows:
- Create file reader ‘const file_reader = new FileReader();’ and read file ‘file_reader.readAsArrayBuffer(e.target.files[0]);’.
- On load event handler call AsposeCropEPS and pass the file content and its name, and left, top, right, bottom bounds of the new box to it.
- The result JSON contains the file name in fileNameResult.
- You can download a file by using the DownloadFile function: ‘DownloadFile(JSON.fileNameResult, “image/pdf”);’.
You can check the quality of Aspose.Page EPS Crop and view the results via free online Crop EPS and than view the resulting EPS file with our EPS Viewer web application.
Crop EPS in Node.js
In the following Node.js code snippet we get the existing bounding box of the image and crop EPS:
1const AsposePage = require('asposepagenodejs');
2
3const eps_file = "./data/PAGENET-361-10.eps";
4
5console.log("Aspose.Page for Node.js via C++ examples.");
6
7AsposePage().then(AsposePageModule => {
8
9 //CropEPS - working with EPS
10 const JSON = AsposePageModule.AsposeCropEPS(eps_file, "croped.eps", 30, 5, 240, 36);
11 console.log("CropEPS => %O", JSON.errorCode == 0 ? JSON.parse(JSON.stringify(JSON).replace('"errorCode":0,"errorText":"",','')) : JSON.errorText);
12
13},
14 reason => {console.log(`The unknown error has occurred: ${reason}`);}
15);
Initial image
Cropped image
Evaluate cropping EPS online on our Crop EPS web application. You can crop EPS file and dowload result in a few seconds.
You can download examples and data files from
GitHub.