Skip to content

Foxit PDF SDK Node.js Library ​

This section describes how to run samples and create a basic project using the Foxit PDF SDK Node.js library. The project demonstrates rendering the first page of a PDF document to a bitmap and saving it as a JPG image.

Prerequisites ​

Development environment ​

  • Node.js version: Supports v10–v22.
  • Foxit PDF SDK Node.js library: Request a trial via the Foxit Developer Hub. Download and install the library that matches your OS and architecture.

System support ​

We provide detailed system support information for Windows, Linux, and macOS, including operating system versions and compiler requirements. Select your platform to view the details.

Windows Linux MacOS

Setup ​

Install the SDK Node.js library ​

Open a command-line or terminal window, navigate to the root directory, and install the Foxit PDF SDK Node.js module with the following command:

shell
npm i @fuxinsoft/foxit-pdf-sdk-node

Run samples ​

Run all samples ​

  • See Samples for an overview of the sample projects, dependency information for specific samples, and instructions for running samples from the command line.

Run a specific sample ​

  • Navigate to the sample directory, for example \examples\simple_demo\ocr, and run node ocr.js.

Quick start ​

  1. Create a project directory:

    • Create a folder named test as the project directory.
  2. Prepare a PDF file:

    • Copy SamplePDF.pdf from /example/simple_demo/input_files into the test folder.
  3. Install the SDK module:

    • In the test folder, run npm install @fuxinsoft/foxit-pdf-sdk-node from the command line to install the Foxit PDF SDK Node.js module.
  4. Create a Node.js script:

    • In the test folder, create a Node.js script named test.js and copy the following code into the file:
    [test.js]
    js
    const FSDK = require("@fuxinsoft/foxit-pdf-sdk-node");
    
    # Assuming PDFDoc doc has been loaded.
    # The value of "sn" can be got from "gsdk_sn.txt" (the string after "SN=").
    # The value of "key" can be got from "gsdk_key.txt" (the string after "Sign=").
    var sn = " "
    var key = " "
    FSDK.Library.Initialize(sn, key);
    
    // Load a PDF document, and parse the first page of the document.
    let doc = new FSDK.PDFDoc("SamplePDF.pdf");
    let error_code = doc.Load("");
    if(error_code!= FSDK.e_ErrSuccess) {
      return;
    } 
    
    let page = doc.GetPage(0);
    page.StartParse(FSDK.PDFPage.e_ParsePageNormal, null, false);
    
    let width = page.GetWidth();
    let height = page.GetHeight();
    let matrix = page.GetDisplayMatrix(0, 0, width, height, page.GetRotation());
    
    // Prepare a bitmap for rendering.
    let bitmap = new FSDK.Bitmap(width, height, Bitmap.e_DIBArgb, null, 0);
    bitmap.FillRect(0xFFFFFFFF, null);
    // Render page.
    render = Renderer(bitmap, false)
    render.StartRender(page, matrix, null)
    
    // Add the bitmap to image and save the image.
    let img = new FSDK.Image();
    img.AddFrame(bitmap);
    img.SaveAs("testpage.jpg");
    FSDK.Library.Release();
  5. Run the script:

    • In the command line, switch to the test folder and run node test.js.
    • If the script runs successfully, a testpage.jpg file is generated in the test folder containing the rendered first page of the PDF document.