Build a Node.js PDF library app with Apryse Server SDK
This guide shows how to build a simple Node.js PDF application that uses the Apryse Server SDK and PDFNet library to generate a PDF programmatically. You’ll set up a minimal project, install the SDK, and add the required code to create a blank PDF document. This example provides a practical foundation for building more advanced document‑generation workflows.
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.
1. Set up your project
Set up your project by creating a folder and preparing your workspace for the application.
In your file manager, create a Documents > NewApryseProject folder.
Right-click the NewApryseProject folder and select Open in Terminal.
In your terminal, initialize a new Node.js project to generate a default
package.jsonfile:
npm init -yA successful output looks similar to:
2. Add the Apryse SDK
Next, integrate the Apryse Server SDK into your Node.js application and add the code needed to generate a PDF.
Navigate to the
Documents\NewApryseProjectdirectory in your terminal, then install the Apryse SDK:
In Visual Studio Code, go to File > New Text File.
Paste this code into the text editor, update your license key, and save the file in the
Documents\NewApryseProjectdirectory asindex.js:
With this code, you can:
Log a startup message to confirm the application is running.
Import the Apryse Node.js SDK.
Define an asynchronous
mainfunction that creates a new PDF document, adds a blank page, and saves it as a linearized PDF.Use
runWithCleanupto initialize the SDK, execute the main function, and handle cleanup automatically.Handle errors and shut down the
PDFNetengine 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.
Go to the Documents > NewApryseProject folder, and right-click to select Open in Terminal.
In the terminal, build and launch the application:
A successful output looks similar to:
Go to the Documents > NewApryseProject folder using the file manager.
Verify the blank
output.pdffile was generated programmatically using the Apryse Server SDK:
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.
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. Set up your project
Set up your project by creating a folder and preparing your workspace for the application.
In your file manager, create a Documents > NewApryseProject folder.
Right-click the NewApryseProject folder and select Open in Terminal.
In your terminal, initialize a new Node.js project to generate a default
package.jsonfile:
A successful output looks similar to:
2. Add the Apryse SDK
Next, integrate the Apryse Server SDK into your Node.js application and add the code needed to generate a PDF.
Navigate to the
Documents/NewApryseProjectdirectory in your terminal, then install the Apryse SDK:
In Visual Studio Code, go to File > New Text File.
Paste this code into the text editor, update your license key, and save the file in the
Documents/NewApryseProjectdirectory asindex.js:
With this code, you can:
Log a startup message to confirm the application is running.
Import the Apryse Node.js SDK.
Define an asynchronous
mainfunction that creates a new PDF document, adds a blank page, and saves it as a linearized PDF.Use
runWithCleanupto initialize the SDK, execute the main function, and handle cleanup automatically.Handle errors and shut down the
PDFNetengine 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.
Go to the Documents > NewApryseProject folder, and right-click to select Open in Terminal.
In the terminal, build and launch the application:
A successful output looks similar to:
Go to the Documents > NewApryseProject folder using the file manager.
Verify the blank
output.pdffile was generated programmatically using the Apryse Server SDK:
Prerequisites
A version of Node.js supported by AWS Lambda (up to v24)
An active AWS account
Docker (optional)
Initial Setup
In this particular guide, we will demonstrate how to set up an AWS Lambda function to use the Apryse SDK with Node.js.
First, you will have to prepare a deployment package with the pdfnet-node module and your Lambda function code (typically named index.js) within it. From the command line:
Now, copy your lambda function code to YOUR_FUNCTION_FOLDER.
It's at this point that it is important to note that the pdfnet-node module must be installed using the same operating system that AWS Lambda will use for its runtime. This is dependent on on the version of Node.js you are using. To see which operating system is required, look here.
We recommend that you use a Docker container to simulate this runtime and have included a Dockerfile to do just that. Create a Dockerfile with the contents below.
Next, run the following docker commands to generate a deployment package to upload to AWS Lambda. Replace YOUR_IMAGE_NAME_HERE with the image name of your choice, as well as YOUR_NODE_VERSION_HERE as the Node version of your choice. YOUR_NODE_VERSION_HERE as the Node version of your choice. Note that this Dockerfile requires that your AWS Lambda function code file be named index.js, and that it uses your project's package.json and package-lock.json to install dependencies such as the pdfnet-node module you installed in the last step.
After running this Docker container, you should have your deployment package within the ./output directory and can now upload it to AWS Lambda.
Second, create a Lambda function in your AWS account and upload the deployment package:
Lambda > Functions > Create function > Author from scratch > Function name [
YOUR_FUNCTION_NAME] > Runtime (matching your Node version) > choose Create FunctionUpload from .zip file > Upload [your deployment package] > Save
Add trigger > API Gateway > Create an API > REST > Security [Open]
Configuration > General configuration > Edit > memory [Choose 10240MB]
Integrate Into Your Application
Once you have followed the initial setup instructions, you can begin calling Apryse SDK APIs in your Lambda function code. For example:
Run Sample Code
You can update the Node.js script of your AWS Lambda function with the following code or download the source code from our GitHub repository. This snippet shows how to process a request sent from a client, convert an office document to a PDF, and send the output to client.
Testing
After you have uploaded your deployment package to AWS Lambda and set its API endpoint in Configuration > Triggers, you can now do a simple test using a REST API.
In order to use the function to convert an office document to PDF, the client needs to POST a REST API request to the server. The request must include JSON data structured as in the code below.
Upon receiving a client's request, a response will be sent back to the client including the base64 encoded PDF output using the same JSON structure. All the client needs to do now is decode the encoded data into a PDF. That's it! Please review the sample python code. After cloning the repository and installing necessary packages, please refer to /client/README.txt for detailed instructions. Navigate to the client folder, run the following command, see the response to client's request in the console, and check the output in the output folder:
The client will send a REST API request to convert /input/simple-word_2007.docx to a PDF and the server will send back the encoded data, which will then be saved as PDF in the output folder.
You can experiment with your own office document by putting it inside input folder:
In this article, we have shown how to set up an AWS Lambda function using the Apryse SDK. You can now experiment making your own functions, URLs, and can fully utilize the Apryse SDK using AWS Lambda. If your have any questions, please don't hesitate to contact us!
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.
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. Set up your project
Set up your project by creating a folder and preparing your workspace for the application.
In your file manager, create a Documents > NewApryseProject folder.
Right-click the NewApryseProject folder and select New Terminal at Folder.
In your terminal, initialize a new Node.js project to generate a default
package.jsonfile:
A successful output looks similar to:
2. Add the Apryse SDK
Next, integrate the Apryse Server SDK into your Node.js application and add the code needed to generate a PDF.
Navigate to the
Documents/NewApryseProjectdirectory in your terminal, then install the Apryse SDK:
In Visual Studio Code, go to File > New Text File.
Paste this code into the text editor, update your license key, and save the file in the
Documents/NewApryseProjectdirectory asindex.js:
With this code, you can:
Log a startup message to confirm the application is running.
Import the Apryse Node.js SDK.
Define an asynchronous
mainfunction that creates a new PDF document, adds a blank page, and saves it as a linearized PDF.Use
runWithCleanupto initialize the SDK, execute the main function, and handle cleanup automatically.Handle errors and shut down the
PDFNetengine 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.
Go to the Documents > NewApryseProject folder, and right-click to select New Terminal at Folder.
In the terminal, build and launch the application:
A successful output looks similar to:
Go to the Documents > NewApryseProject folder using the file manager.
Verify the blank
output.pdffile was generated programmatically using the Apryse Server SDK. The folder structure looks similar to:
Get started video
Get started with the Apryse Server SDK and Node.js on the Windows platform by watching this 4-minute video.
Next Steps
Last updated
Was this helpful?