Node.js PDF library integration

Welcome to Apryse. Node.js for the Apryse SDK is supported on Windows, Linux and macOS. To get started, choose your preferred platform from the tabs below.

Windows Node.js PDF library integration

This guide will help you run Apryse samples and integrate a free trial of the Apryse SDK into Node.js projects on Windows. Your free trial includes unlimited trial usage and support from solution engineers.

Download the SDK

Download

Prerequisites

  • Windows (64-bit)
  • Node.js Version: 8 - 22

Run Apryse SDK in production

A commercial license key is required for use in a production environment. Please contact sales to purchase a commercial key or if you need any other license key assistance.

Keep your commercial license key confidential.

License keys are uniquely generated. Please make sure that it is not publicly available (e.g. in your public GitHub).

Initial setup

  1. Install the npm package:

Please note that all Apryse NodeJS libraries install native binaries and installing the package will install a system specific distribution.

sh

1npm i @pdftron/pdfnet-node

If your OS or Node.js version is not supported, the installation will fail.

2. Get your Apryse trial key.

The Apryse SDK requires a license key. it's free to get a trial one.\

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 the samples

The samples are not included with the pdfnet-node package, and need to be downloaded separately.

Step 1 - Download the samples

Open a command line console, and run

sh

1npm i @pdftron/pdfnet-node-samples

Step 2 - Navigate to the folder where the samples are located

Change the directory to the node_modules/@pdftron/pdfnet-node-samples folder

Step 3 - Add the license key to the sample

The Apryse SDK requires a license key. Open the file LicenseKey.js, and paste the license key into it.

JavaScript

LicenseKey.js

1//"Enter your key here. If you don't have it, 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.
2const LicenseKey = 'YOUR_PDFTRON_LICENSE_KEY';
3if(LicenseKey == 'YOUR_PDFTRON_LICENSE_KEY'){
4 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.');
5}
6exports.Key = LicenseKey;

Step 4 - Run the samples

While you can run samples individually, you can also run all of them together using a script that is in package.json.

sh

1npm run test

If you want to run a sample individually, then navigate to its folder, then use node to run the JavaScript file. For example, here's how to run the AddImageTest sample:

sh

1cd ./AddImageTest
2node AddImageTest.js

Integrate into your project

You can now import the Apryse SDK by using the following in your Node.js code:

JavaScript

1const { PDFNet } = require('@pdftron/pdfnet-node');

At the end of your code, don't forget to call PDFNet.shutdown(), otherwise your Node.js program will keep hanging.

Here is an example for creating a blank pdf page:

JavaScript

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

Next step

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales