Get started with the Apryse Server SDK Python PDF library integration

Use our Apryse Server SDK with Python3 and pip3. We include Python examples to integrate Server.

The Apryse Server SDK is cross-platform and supported on Windows, Linux, and macOS. The base package is robust, allowing you to programmatically do the following with PDFs:

Additional functionality

If you’re looking for additional capabilities, we offer add-on packages, such as Smart Data Extraction, and add-on modules, such as Office Conversion. For a complete list of add-ons, refer to the following:

Solutions and benefits

Using the Server SDK allows you to build server-side document processing solutions at scale without relying on client devices or cloud APIs. Since the Server runs entirely on-premises (or in your private cloud), you can ensure security and compliance with full control over access, storage, and encryption. You can also easily integrate with web apps, backend systems, document management systems, and content workflows.

Steps and samples

This get-started guide explains how to install and use the Apryse Server SDK in a Python application. It includes the full Python 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.

There are two ways to use Apryse with Python:

  • Use pip to install third‑party Python packages, such as the Apryse SDK. The SDK is distributed as a precompiled Python library.
  • Use PDFNet bindings to build your own custom Python wrapper (less common).

This guide walks you through getting started with the precompiled Python SDK using pip.

Choose your preferred platform from these tabs.

Windows Python PDF library integration

In this guide, you'll begin by setting up your Python environment. Next, 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 Python application, add the Apryse Server SDK, and learn how to generate files programmatically.

Prerequisites

Before you start:

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. Set up Python and pip

Before getting started, ensure that Python and pip are installed. You’ll use pip to install the Apryse Server SDK.

  1. Check whether Python and pip are installed:

Shell

1python --version
2pip --version

2. If Python and pip aren't installed, download any supported Python 3 version and run the installer from your Downloads folder. During installation:

  • Use admin privileges.
  • Select Add Python to PATH.
  • Enable pip and venv.

3. If Python and pip are installed, run the following command to update:

Shell

1python -m pip install --upgrade pip

2. 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.

  1. Download the PDFNetPython3.zip file.
  2. In Documents, create a new ApryseSamples folder. Use a different location if preferred.
  3. Go to Downloads, right-click the PDFNetPython3.zip file, and select Extract All.
  4. Click Browse, find and select the ApryseSamples folder you created.
  5. Click Extract to unzip the files to the new ApryseSamples folder.
  6. Navigate to this location, right-click, and select Open in Terminal:

Text

1C:\Users\<your_name>\Documents\ApryseSamples\Samples\OfficeToPDFTest\PYTHON

7. In the terminal, install the Apryse SDK using pip to fetch the package from Apryse's package index:

Info

Install the Apryse SDK in a virtual environment to ensure it's isolated and installed in a predictable location. When running Python scripts that import apryse-sdk, make sure you activate the same virtual environment first.

Shell

1pip install apryse-sdk --extra-index-url=https://pypi.apryse.com

The message Successfully installed apryse-sdk ... appears in the terminal.

Info

The legacy PDFNetPython3 package on the default Python Package Index (PyPI) is no longer maintained.

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

Text

1C:\Users\<your_name>\Documents\ApryseSamples\Samples\LicenseKey\PYTHON\LicenseKey.py
2

9. Go to the 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.

Python

LicenseKey.py

1# Add your trial license key here
2LicenseKey = "YOUR_PDFTRON_LICENSE_KEY"
3if LicenseKey == "YOUR_PDFTRON_LICENSE_KEY":
4 raise Exception("Please enter your license key by replacing \"YOUR_PDFTRON_LICENSE_KEY\" that is assigned to the LicenseKey variable in Samples/LicenseKey/PYTHON/LicenseKey.py. 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

10. To run the sample, navigate to this folder, right-click, and select Open in Terminal:

Text

1C:\Users\<your_name>\Documents\ApryseSamples\Samples\OfficeToPDFTest\PYTHON

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

Shell

1python -u .\OfficeToPDFTest.py

When you run the command, the sample code 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.

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

Text

1C:\Users\<your_name>\Documents\ApryseSamples\Samples\TestFiles\Output

The folder structure looks similar to:

Text

1Samples/TestFiles/Output/
2├── factsheet_Arabic.pdf
3├── Fishermen.pdf
4├── the_rime_of_the_ancient_mariner.pdf

13. Open the PDF files to see the converted output. The original DOCX files are located in the PDFNetC64\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

3. Create a Python PDF app

Create a simple Python 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. In Visual Studio Code or your preferred editor, go to File > Open Folder.
  3. Find the NewApryseProject folder and click to Open in Visual Studio Code.
  4. Create a HelloWorld.py file at the root of your project.

Add the SDK to your app

Next, integrate the Apryse Server SDK into your Python 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 using pip to fetch the package from Apryse's package index:

Info

Install the Apryse SDK in a virtual environment to ensure it's isolated and installed in a predictable location. When running Python scripts that import apryse-sdk, make sure you activate the same virtual environment first.

Shell

1python3 -m pip install apryse-sdk --extra-index-url=https://pypi.apryse.com

A successful output looks like:

Shell

1Looking in indexes: https://pypi.org/simple, <additional index>
2Collecting apryse-sdk
3 Downloading apryse_sdk-<version>.whl
4Installing collected packages: apryse-sdk
5Successfully installed apryse-sdk-<version>

Info

The legacy PDFNetPython3 package on the default Python Package Index (PyPI) is no longer maintained.

2. Open the HelloWorld.py file in Visual Studio Code or your preferred code editor:

Text

1C:\Users\<your_name>\Documents\NewApryseProject\HelloWorld.py

3. Add this code to the HelloWorld.py file, update your license key, and save your changes:

Python

HelloWorld.py

1# You can add the following line to integrate apryse-sdk
2# into your solution from anywhere on your system so long as
3# the library was installed successfully via pip
4
5from apryse_sdk import *
6
7def main():
8
9 # Initialize Apyrse SDK
10 # Replace with you demo license key
11 PDFNet.Initialize("YOUR_LICENSE_KEY")
12
13 try:
14 # This example creates a new document
15 # and a new page, then adds the page
16 # in the page sequence of the document
17 doc = PDFDoc()
18
19 page1 = doc.PageCreate()
20 doc.PagePushBack(page1)
21
22 # Save the document in a linearized
23 # format which is the most popular and
24 # effective way to speed up viewing PDFs
25 doc.Save(("output.pdf"), SDFDoc.e_linearized)
26
27 doc.Close()
28 except Exception as e:
29 print("Unable to create PDF document, error: " + str(e))
30
31 PDFNet.Terminate()
32
33if __name__ == "__main__":
34 main()

With this code, you can:

  • Import and initialize the Apryse Python SDK using your license key.
  • Create a new PDF document and add a blank page.
  • Save the document as a linearized PDF for optimized viewing.
  • Perform document operations using the PDFNet API—in this case, creating and modifying a PDFDoc object.
  • Close the document after saving.

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, run the HelloWorld.py script:

Shell

1python.exe -u HelloWorld.py

A successful output looks similar to:

Shell

1PDFNet is running in demo mode.
2PackageV2: base

3. Navigate to the Documents > NewApryseProject folder.

4. Verify the blank output.pdf file was generated programmatically using the Apryse Server SDK. The folder structure looks similar to:

Text

1NewApryseProject/
2├── HelloWorld.py
3└── output.pdf

Now that you've successfully run an OfficeToPDFTest sample (in section 2) and integrated the Apryse Server SDK Python 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 2. Convert DOCX to PDF, then choose a different sample to run.

Info

Additional modules are required for some sample functionality, such as OCR, CAD, and PDF-to-Microsoft Office. For more, see Add-on modules for Apryse Server SDK.


Related Blogs

How to Build Optical Character Recognition (OCR) in Python - 1/16/25

Splitting a PDF Using Python - 9/11/24

PDF to Office Document Conversion Using Apryse and Python - 4/4/24

Generating Documents and Reports from DOCX Templates and JSON using Apryse and Python - 10/9/23

A Guide to PDF Data Extraction Using Apryse SDK and Python - 7/20/23

Adding a Digital Signature to a PDF With the Python SDK - 7/13/23

How to Extract Text from a PDF Using Python - 12/9/22

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales