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

In this guide, you'll create a simple Node.js application, add the Apryse Server SDK, and learn how to generate a pdf file programmatically.

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

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.

1. Set up your project

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

  1. Within your Documents folder, create a new NewApryseProject folder.
  2. From the terminal, within your new folder, 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

2. Add the Apryse SDK

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.

3. Verify your output

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 in your terminal.
  2. 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

Get started video

Get started with the Apryse Server SDK and Node.js on the Windows platform by watching this 4-minute video.

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

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