Get started with the Apryse Server SDK Python PDF library integration

This get-started guide explains how to set up your Python environment and install and use the Apryse Server SDK in a Python application. We'll 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.

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

3. 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 \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

1python -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.

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

  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


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