Get started with the Apryse Server SDK Node.js PDF library integration

The Apryse Server SDK delivers powerful, high-quality document processing for your backend infrastructure, is cross-platform, and supported on Windows, Linux, and macOS. Our sophisticated library provides advanced rendering, conversion, and manipulation capabilities for popular formats, including PDF, MS Office, CAD, and various image types. Automate complex workflows, like server-side generation, batch conversion, merging, or pre-processing documents, without relying on client-side tools.

By managing all document services on your servers, you gain complete control, compliance, and security over your data. Integrate this fully-featured server SDK to build scalable, high-performance applications with superior document functionality out-of-the-box.

The Apryse Server SDK base package is scalable, allowing you to easily embed   document processing into your backend applications. If you’re looking for additional capabilities, we offer add-on packages, such as Smart Data Extraction, and add-on modules, such as Digital Signatures and Office Conversion.

Steps and samples

This get-started guide explains how to install and use the Apryse Server SDK in a Node.js application. It includes the full Node.js PDF library and sample modules. We'll focus on the OfficeToPDFTest sample to convert Office documents to PDF and demonstrate how to build a simple app for programmatic PDF generation.

Get started video

Get started with the Apryse Server SDK and Node.js on the Windows platform by watching this 4-minute video. You can skip the video and follow the step-by-step instructions instead.

Get started video for Apryse Server SDK and Node.js on Windows

To get started, choose your preferred platform from the tabs below.

Windows Node.js PDF library integration

In this guide, you'll explore sample PDFNet projects to understand the types of PDF outputs you can create with the Apryse Server SDK. You'll also create a simple Node.js application, add the Apryse Server SDK, and learn how to generate files programmatically.

Prerequisites

Before you start:

  • Install Visual Studio Code or another code editor to develop and debug your code.
  • Install Node.js and npm for your runtime environment. Use the latest active LTS version of Node.js within the supported range (Node.js 10.x–24.x).
  • Get your Apryse trial key.

License Key

Apryse collects some data regarding your usage of the SDK for product improvement.

If you wish to continue without data collection, contact us and we will email you a no-tracking trial key for you to get started.

Run Apryse SDK in production.

A commercial license key is required for use in a production environment. Contact sales to purchase a commercial license key.

Keep your commercial license key confidential.

License keys are uniquely generated and strictly confidential. Don't publish or store them in any public location, including public GitHub repositories.

1. Convert DOCX to PDF

In this section, you’ll use the OfficeToPDFTest sample to convert a DOCX file to PDF using the Microsoft Office conversion API. You can use this sample to understand how document conversion works and as a reference for your own implementations.

Info

Apryse Node.js libraries include native binaries. During installation, the correct distribution for your system is installed automatically.

  1. Open your Windows terminal and install the Apryse Node.js PDF library:

Shell

1npm i @pdftron/pdfnet-node

2. Install the pdfnet-node-samples library, which contains a collection of sample projects:

Shell

1npm i @pdftron/pdfnet-node-samples

3. To add your license key, open this file in Visual Studio Code:

Text

1C:\Users\<your_name>\node_modules\@pdftron\pdfnet-node-samples\LicenseKey\LicenseKey.js

4. Go to the const LicenseKey = ‘YOUR_PDFTRON_LICENSE_KEY’; line and replace the quoted text with your trial license key. Don't change any other information in this file. Save your changes.

JavaScript

LicenseKey.js

1// Add your trial license key here
2const LicenseKey = 'YOUR_PDFTRON_LICENSE_KEY';
3
4if(LicenseKey == 'YOUR_PDFTRON_LICENSE_KEY'){
5 throw ('Please enter your license key by replacing \'YOUR_PDFTRON_LICENSE_KEY\' that is assigned to the LicenseKey variable in Samples/LicenseKey/LicenseKey.js. If you do not have a license key, please go to https://www.pdftron.com/pws/get-key to obtain a demo license or https://www.pdftron.com/form/contact-sales to obtain a production key.');
6}
7
8exports.Key = LicenseKey;
9

5. Navigate to this location, right-click, and select Open in Terminal:

Text

1C:\Users\<your_name>\node_modules\@pdftron\pdfnet-node-samples\OfficeToPDFTest

6. In the terminal, add this command to run the sample:

Shell

1node OfficeToPDFTest.js

When you run the node OfficeToPDFTest.js command, the sample loads a Microsoft Office document, converts it to PDF, saves the PDF, and outputs the following status messages to the console. For more details, review the OfficeToPDF sample code and the Convert MS Office (Word, Excel, PowerPoint) to PDF overview.

Shell

1PDFNet is running in demo mode.
2PackageV2: base
3PackageV2: office_conversion
4Saved Fishermen.pdf
5Saved the_rime_of_the_ancient_mariner.pdf
6Saved factsheet_Arabic.pdf
7Done.

7. Go to this directory to verify that the output PDF files are present:

Text

1C:\Users\YourName\node_modules\@pdftron\pdfnet-node-samples\TestFiles\Output

The folder structure looks similar to:

Text

1pdfnet-node-samples/TestFiles/Output/
2├── empty
3├── factsheet_Arabic.pdf
4├── Fishermen.pdf
5└── the_rime_of_the_ancient_mariner.pdf
6

8. Open the PDF files to see the converted output. The original DOCX files are located in the pdfnet-node-samples\Samples\TestFiles folder.

Converted PDF file showing the output generated from a DOCX document

Converted PDF file showing the output generated from a DOCX document

2. Create a Node.js PDF app

Create a simple Node.js application that uses the Apryse Server SDK and PDFNet library to generate a PDF programmatically. In this section, you’ll set up a minimal project, add the required code, and run a script that creates a blank PDF document. This example provides a practical foundation for building more advanced document‑generation workflows.

Set up your project

Set up your project by creating a folder and preparing your workspace for the application.

  1. Go to your Documents folder and create a new NewApryseProject folder.
  2. Right-click the NewApryseProject folder and select Open in Terminal.
  3. In the terminal, initialize a new Node.js project and create a default package.json file:

Shell

1npm init -y

A successful output looks similar to:

Shell

1Wrote to <project_directory>/package.json:
2
3{
4 "name": "<project_name>",
5 "version": "1.0.0",
6 "description": "",
7 "main": "index.js",
8 "scripts": {
9 "test": "echo \"Error: no test specified\" && exit 1"
10 },
11 "keywords": [],
12 "author": "",
13 "license": "ISC",
14 "type": "commonjs"
15}
16

Add the SDK to your app

Next, integrate the Apryse Server SDK into your .NET application and add the code needed to generate a PDF.

1. Navigate to the Documents\NewApryseProject directory in your terminal, then install the Apryse SDK:

Shell

1npm i @pdftron/pdfnet-node

2. In Visual Studio Code, go to File > New Text File.

3. Paste this code into the text editor, update your license key, and save the file in the Documents\NewApryseProject directory as index.js:

JavaScript

index.js

1console.log("Hello World from Node.js!");
2
3const { PDFNet } = require('@pdftron/pdfnet-node'); // you may need to set up NODE_PATH environment variable to make this work.
4
5const main = async () => {
6 const doc = await PDFNet.PDFDoc.create();
7 const page = await doc.pageCreate();
8 doc.pagePushBack(page);
9 doc.save('output.pdf', PDFNet.SDFDoc.SaveOptions.e_linearized);
10};
11
12// Add your own license key as the second parameter, e.g. in place of 'YOUR_LICENSE_KEY'.
13PDFNet.runWithCleanup(main, 'YOUR_LICENSE_KEY')
14 .catch((error)=> {
15 console.log('Error: ' + JSON.stringify(error));
16 })
17 .then(()=> {
18 PDFNet.shutdown();
19 });

Info

If you're signed in with an Apryse account, your license key is automatically prepopulated in all code snippets.

With this code, you can:

  • Log a startup message to confirm the application is running.
  • Import the Apryse Node.js SDK.
  • Define an asynchronous main function that creates a new PDF document, adds a blank page, and saves it as a linearized PDF.
  • Use runWithCleanup to initialize the SDK, execute the main function, and handle cleanup automatically.
  • Handle errors and shut down the PDFNet engine after execution to release resources.

Run and verify your setup

Finally, build and run your application to confirm that the Apryse Server SDK is working correctly. After the application runs successfully, it will generate a blank PDF file locally.

  1. Navigate to the Documents > NewApryseProject folder, and right-click to select Open in Terminal.
  2. In the terminal, build and launch the application:

Shell

1node index.js

A successful output looks similar to:

Shell

1Hello World from Node.js!
2
3PDFNet is running in demo mode.
4PackageV2: base

3. Navigate to the Documents > NewApryseProject folder.

4. Verify the blank output.pdf file was generated programmatically using the Apryse Server SDK:

Text

1NewApryseProject/
2├── node_modules/
3├── index.js
4├── output.pdf
5├── package.json
6└── package-lock.json

Now that you've successfully run an OfficeToPDFTest sample and integrated the Apryse Server SDK Node.js PDF library into your application, you can try out 50+ samples depending on your needs.

File explorer window on a Windows system showing the Apryse Samples library installed

You can try over fifty samples for the Apryse Server SDK.

To try additional samples, go to section 1. Convert DOCX to PDF, then choose another sample to run.

Next Steps

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales