How to add Images to PDF via Node.js SDK
To add images into 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. Simply create an account at Aspose for Cloud and get your application information. 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 add Images to PDF using Node.js
Aspose.PDF Cloud developers can easily load & add Images to PDF in just a few lines of code.
- Reads a local image file and uploads it to the Aspose.PDF Cloud storage.
- Inserts the uploaded image into the uploaded PDF file at a specific location.
- Download the result if needed it
Add Images to PDF using Node.js
import credentials from "./credentials.json" with { type: "json" };
import fs from 'node:fs/promises';
import { PdfApi } from "asposepdfcloud";
async function add() {
const localPdfFile = "C:\\Samples\\Sample.pdf";
const storagePdfFile = "Sample.pdf";
const localImageFile = "C:\\Samples\\images\\sample.png";
const storageImageFile = "Sample.png";
const pdfApi = new PdfApi(credentials.id, credentials.key);
try {
let fileData = await fs.readFile(localPdfFile);
let uploadResult = await pdfApi.uploadFile(storagePdfFile, fileData);
console.log(uploadResult.response.text);
}
catch (error) {
console.error(error.message);
throw error;
}
try {
let fileData = await fs.readFile(localImageFile);
let uploadResult = await pdfApi.uploadFile(storageImageFile, fileData);
console.log(uploadResult.response.text);
}
catch (error) {
console.error(error.message);
throw error;
}
try {
let result = await pdfApi.postInsertImage(
storagePdfFile, // filename
1, // page number
10, 400, 250, 650, // coordinates
storageImageFile);
console.log(result.response);
}
catch (error) {
console.error(error.message);
throw error;
}
}
Work with Images in PDF
Images make documents visually engaging and help break up large blocks of text, making them more attractive to readers. Photos, screenshots, or icons can add context to the content, making it more relatable and meaningful for the audience. Including images in PDFs is essential for creating engaging presentations, user manuals, marketing brochures, and educational materials. Add the Images into PDF documents with Aspose.PDF Cloud Node.js SDK.
With our Node.js library you can:
- 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 change image dimensions in PDF files online and 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