HTML
JPG
PDF
XML
DOCX
PDF
Resize PDF in Node.js Cloud API
API for working with changing size PDF documents using Cloud Node.js SDK
Get StartedHow to Resize PDF via Node.js SDK
To resize 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 resize PDF via Cloud Node.js
Aspose.PDF Cloud developers can easily load & resize PDF in just a few lines of code.
- Initialize the Aspose PDF API
- Upload original document
- Convert the PDF to HTML (XHTML format) and store the result in a temporary folder
- Convert the resulting HTML back to a resized PDF using specified width and height
- Download resulting file if success
Resize PDF using Node.js
import { PdfChangeLayoutHelper, pdfApi } from "./changeLayoutHelper.js";
import path from 'node:path';
import { HtmlDocumentType } from "../../src/models/htmlDocumentType.js";
import { OutputFormat } from "../../src/models/outputFormat.js"
export { PdfResizePages }
const PdfResizePages = {
async resizeAllPages(document, htmlTempDoc, width, height, outputDocument, localFolder, tempFolder) {
await PdfChangeLayoutHelper.uploadDocument(document, localFolder, tempFolder)
const htmlTempPath = path.join(tempFolder, htmlTempDoc);
const html_response = await pdfApi.putPdfInStorageToHtml(
document,
htmlTempPath,
null, null, null, null,
HtmlDocumentType.Xhtml,
null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null,
tempFolder,
null, null,
OutputFormat.Folder);
if (html_response.body.code != 200) {
console.error("resizePages(): Can't convert pdf to html!");
return;
}
else
console.log("resizePages(): temporary file '" + htmlTempDoc + "' succesfully creaated.")
const response = await pdfApi.putHtmlInStorageToPdf(
outputDocument,
htmlTempPath,
htmlTempDoc,
height,
width,
null, null, null, null, null,
tempFolder,
null);
if (response.body.code == 200) {
console.log("resizePages(): Pages successfully resized.");
await PdfChangeLayoutHelper.downloadResult(outputDocument, localFolder, tempFolder, "resized_doc_");
}
else
console.log("resizePages(): Can't convert html to pdf!")
}
}
With our Node.js library you can
Resize 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