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 MacOSSetup
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-nodeRun 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 runnode ocr.js.
Quick start
Create a project directory:
- Create a folder named
testas the project directory.
- Create a folder named
Prepare a PDF file:
- Copy
SamplePDF.pdffrom/example/simple_demo/input_filesinto thetestfolder.
- Copy
Install the SDK module:
- In the
testfolder, runnpm install @fuxinsoft/foxit-pdf-sdk-nodefrom the command line to install the Foxit PDF SDK Node.js module.
- In the
Create a Node.js script:
- In the
testfolder, create a Node.js script namedtest.jsand copy the following code into the file:
[test.js]
jsconst 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();- In the
Run the script:
- In the command line, switch to the
testfolder and runnode test.js. - If the script runs successfully, a
testpage.jpgfile is generated in thetestfolder containing the rendered first page of the PDF document.
- In the command line, switch to the