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.

Linux 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. We used Ubuntu 25.10 to create this guide.

  1. Check whether Python and pip are installed:

Bash

1python3 --version
2python3 -m pip --version
3which python3

On Ubuntu, /usr/bin/python3 is the system Python installed via the Advanced Package Tool (apt) package manager. This is expected and safe to use on Ubuntu systems.

2. If Python and pip aren't installed, or you want to ensure they're up-to-date, run:

Bash

1sudo apt update
2sudo apt install python3 python3-pip python3-venv

The commands install Python 3, pip, and the venv module if they aren't already installed, and update them to the latest versions provided by Ubuntu.

Info

On most Ubuntu systems, the universe repository is already enabled. If a package cannot be found, you may need to enable it.

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. Right-click the downloaded PDFNetPython3.zip file and select Extract to....
  3. Select Home, New Folder, and then enter ApryseSamples as the folder name.
  4. Click Create, then Select to unzip the file into your new ApryseSamples folder and to run the samples. Use a different location if preferred.
  5. Navigate to this location, right-click, and select Open in Terminal:

Text

1~/ApryseSamples/PDFNetPython3/Samples/OfficeToPDFTest/PYTHON

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

Bash

1python3 -m pip 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.

7. To add your license key, navigate to this file and double-click to open it:

Text

1~/ApryseSamples/PDFNetPython3/Samples/LicenseKey/PYTHON/LicenseKey.py

8. 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.")

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

Text

1~/ApryseSamples/PDFNetPython3/Samples/OfficeToPDFTest/PYTHON

10. In the terminal, run this script:

Bash

1chmod +x RunTest.sh
2./RunTest.sh

When you run the RunTest.sh script, 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.

Bash

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

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

Text

1~/ApryseSamples/PDFNetPython3/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

12. Open the PDF files to see the converted output. The original DOCX files are located in the PDFNetPython3/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 Home directory 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 Apryse SDK

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

  1. Navigate to the ~/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.

Bash

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

A successful output looks like:

Bash

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

1~/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 Apryse SDK
10 # Replace with your demo license key
11 PDFNet.Initialize("YOUR_LICENSE_KEY")
12
13 # This example creates a new document
14 # and a new page, then adds the page
15 # in the page sequence of the document
16 doc = PDFDoc()
17
18 page1 = doc.PageCreate()
19 doc.PagePushBack(page1)
20
21 # Save the document in a linearized
22 # format which is the most popular and
23 # effective way to speed up viewing PDFs
24 doc.Save(("output.pdf"), SDFDoc.e_linearized)
25
26 doc.Close()
27
28if __name__ == "__main__":
29 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 your application

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 Home > NewApryseProject folder, and right-click to select Open in Terminal.
  2. In the terminal, run the HelloWorld.py script:

Bash

1python3 -u HelloWorld.py

A successful output looks similar to:

Bash

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 Linux 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