Ernte -EPS | JavaScript -API -Lösung
Overview
This article explains how to crop EPS using JavaScript. It covers the following topics.
JavaScript Crop EPS Description
Cropping an image involves adjusting one or more of its margins - left, right, top, or bottom - effectively cutting content from the edges.
When you crop an EPS image using our solution, the resulting image will always be smaller than the original. However, the file size itself won’t change because our tool modifies the EPS file’s header, not its content.
An EPS image’s margins are defined by its BoundingBox metadata. To crop, or set a new bounding box, you first need to know the existing bounding box of the EPS image. Failing to do so or setting new bounding box values outside the existing ones will result in an error.
So the steps for cropping EPS image in JavaScript 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 JavaScript
In the following JavaScript code snippet we get existing bounding box of the image and crop EPS:
1 var fCropEPS = function (e) {
2 const file_reader = new FileReader();
3 file_reader.onload = (event) => {
4 const JSON = AsposeCropEPS(event.target.result, e.target.files[0].name, e.target.files[0].name + "_crop.eps", 30, 5, 240, 36);
5 if (JSON.errorCode == 0) {
6 DownloadFile(JSON.fileNameResult, "image/eps");
7 }
8 else
9 document.getElementById('output').textContent = JSON.errorText;
10 }
11 file_reader.readAsArrayBuffer(e.target.files[0]);
12 }
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.