HTML
JPG
PDF
XML
DOCX
PDF
Crop PDF in Node.js Cloud API
API for working with cropping PDF documents using Cloud Node.js SDK
Get StartedHow to Crop PDF via Node.js SDK
To crop PDF, we’ll use Aspose.PDF Cloud Node.js SDK. This Cloud SDK assists Node.js programmers in developing cloud-based PDF creator, annotator, editor, and converter apps using Node.js programming language via Aspose.PDF REST API. Once you have the App SID & key, you are ready to give the Aspose.PDF Cloud Node.js SDK.
Package Manager Console Command
npm install asposepdfcloud --save
Steps to crop PDF via Cloud Node.js
Aspose.PDF Cloud developers can easily load & crop PDF in just a few lines of code.
- Initialize the Aspose PDF API
- Upload original document
- Get page size info
- Extract page as image (full original page)
- Create a new PDF with the specified cropped size
- Insert cropped image portion into new PDF
- Download resulting file if success
Crop PDF using Node.js
import { PdfChangeLayoutHelper, pdfApi } from "./changeLayoutHelper.js";
export { PdfCropPage };
const PdfCropPage = {
async cropPage(document, pageNumber, llx, lly, width, height, outputDocument, localFolder, tempFolder) {
if ( pdfApi ) {
await PdfChangeLayoutHelper.uploadDocument(document, localFolder, tempFolder);
var pageSie = await PdfChangeLayoutHelper.getPageInfo(document, pageNumber, tempFolder);
const imageFile = await PdfChangeLayoutHelper.extractPdfPage(document, pageNumber, pageSie.width, pageSie.height, localFolder, tempFolder);
const newPdf = await PdfChangeLayoutHelper.createPdfDocument(outputDocument, width, height, tempFolder);
if (newPdf.body.code != 200) {
console.error("cropPage(): Failed to create new PDF document!");
return;
}
const response = await PdfChangeLayoutHelper.insertPageAsImage(outputDocument, imageFile, llx, lly, tempFolder);
if (response.body.code == 200) {
console.log("cropPage(): Page successfully cropped.");
await PdfChangeLayoutHelper.downloadResult(outputDocument, localFolder, tempFolder, "cropped_")
}
else
console.error("cropPage(): Can't crop pdf document page!")
}
}
}
With our Node.js library you can
Crop PDF documents with Aspose.PDF Cloud Node.js SDK.
- Add PDF document’s header & footer in text or image format.
- Add tables & stamps (text or image) to PDF documents.
- Append multiple PDF documents to an existing file.
- Work with PDF attachments, annotations, & form fields.
- Apply encryption or decryption to PDF documents & set a password.
- Delete all stamps & tables from a page or entire PDF document.
- Delete a specific stamp or table from the PDF document by its ID.
- Replace single or multiple instances of text on a PDF page or from the entire document.
- Extensive support for converting PDF documents to various other file formats.
- Extract various elements of PDF files & make PDF documents optimized.
- You can try out our free App to test the functionality.
- Learning Resources
- Documentation
- Source Code
- API References
- Product Support
- Free Support
- Paid Support
- Blog
- Why Aspose.PDF Cloud for Node.js?
- Customers List
- Security