Add Images to PDF document via JavaScript

Insert images to PDF document programmatically using Aspose.PDF for Node.js via C++ Library

Add Image to PDF Document Using JavaScript Library

Adding images to a PDF can enhance the visual appeal of the document. Images can be used to illustrate concepts, provide examples, or showcase products, making the PDF more engaging and informative. In order to add an image into PDF file, we’ll use Aspose.PDF for Nodejs via C++ is a easy and secure toolkit used to work with PDF directly in the web browser. To install and use Aspose.PDF for JavaScript via C++ extract files from the ZIP archive.

Add Image to PDF using JavaScript


You need Aspose.PDF for Node.js via C++ to try the code in your environment.

  1. Import the Aspose.PDF module.
  2. Define a constant for output file.
  3. Define a constant for image file.
  4. Call the AsposePdf function.
  5. Call the AsposePdfAddImage method.
  6. Use the console.log method to print the result.

Add Image to PDF document - JavaScript

This sample code shows how to add Images into PDF page - JavaScript

const AsposePdf = require('../AsposePDFforNode.js');
const pdf_file = '../ReadMe.pdf';
const image_file = '../Aspose.jpg';
AsposePdf().then(AsposePdfModule => {
    /*Add image to end a PDF-file and save the "ResultImage.pdf"*/
    const json = AsposePdfModule.AsposePdfAddImage(pdf_file, image_file, "./ResultAddImage.pdf");
    console.log("AsposePdfAddImage => %O", json.errorCode == 0 ? json.fileNameResult : json.errorText);
});