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.

macOS 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:

  • Install Visual Studio Code or another code editor to develop and debug code.
  • Install Python 3 and pip. In this guide, we use Homebrew to manage the Python installation.
  • 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.

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

1. Install or update Python and pip

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

Info

macOS includes a system‑managed Python used by the operating system. For development, install Python via Homebrew and use it inside a virtual environment.

  1. Check to see if Python and pip are installed:

Bash

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

The python3 path should point to Homebrew (for example, /opt/homebrew/bin/python3 or /usr/local/bin/python3). If it points to /usr/bin/python3, you're using the system Python.

2. If Python and pip aren't installed, install them with Homebrew. This command installs the latest Python version with pip:

Bash

1brew install python

3. If Python and pip are installed with Homebrew, update Homebrew and Python. This also updates pip:

Bash

1brew update
2brew upgrade python

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. Double-click the downloaded PDFNetPython3.zip file to unzip it.
  3. In your Documents folder, create a new ApryseSamples folder for the sample files. Use a different location if preferred.
  4. Move the unzipped PDFNetPython3 folder to the new ApryseSamples folder.
  5. Navigate to this location, right-click, and select New Terminal at Folder:

Text

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

6. In the terminal, install the Apryse SDK using pip to fetch the package from Apryse's package index. The legacy PDFNetPython3 package on the default Python Package Index (PyPI) is no longer maintained:

Bash

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

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.

If no errors occur, Successfully installed apryse-sdk... displays in the terminal.

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

Text

1~/Documents/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.")
5

9. To run the sample, navigate to this folder:

Text

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

10. Right-click the PYTHON folder and select New Terminal at Folder.

11. 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
7Done.

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

Text

1~/Documents/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

13. 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 .NET 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:

Bash

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

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.

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>

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

Text

1~/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 as 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 # We 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()

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:

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

Bash

1python -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 macOS system showing the Apryse Samples library installed

You can try over fifty samples for the Apryse Server SDK.

To try additional samples, go to 2. Convert DOCX to PDF > Step 11 and 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