Get Started with the Apryse Server SDK Python 3 PDF Library Integration

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 guide walks you through steps to work through samples we give you, create a project, and integrate the Apryse Server SDK free trial into your project. We’ll use a Python project as our example project throughout this guide. By the end, you’ll have run through at least one sample, created a project, and built an "Apryse Hello World" within your application.

How to use Apryse with Python

There are two ways to use Apryse with Python:

  • Use pip3 which installs third party Python packages (for example, the Apryse SDK for Python 3). It’s the precompiled library for Python 3.x.
  • Use PDFNet bindings to build your own wrappers (less common).

This guide will get you started using the precompiled Python for 3.x through pip3.

Choose your preferred platform from the tabs below.

Precompiled Python3 and Windows PDF library integration

You'll install or update pip3 and Python3, then get started with our samples to see the output you can create when you integrate the Apryse Server SDK into your application. Last, you'll create a project and integrate the Server SDK into your Python 3 application, all while using the Windows platform.

Prerequisites

Before you start:

  • Install Visual Studio Code (or your preferred application) to write, edit, and debug source code.
  • 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. Please fill out our licensing form if you do not have a valid 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/Update Python3 and pip3

You’ll need Python3 in your system. You’ll need pip3 to eventually install the Apryse Server SDK.

  1. Check to see if Python3 and pip3 are installed on your system:

sh

1python --version
2pip --version

2. Complete one of the following based on whether pip3 and Python3 are already installed:

  • OPTION 1: Install Python3 and pip3 if they're not installed:
    • To download Python3, go to the Python Windows download page, then select the file you need. You can use any Python3 version Python supports.
    • Click on the executable in your Downloads folder to start installation. Make sure to check the box before the actual install to set Python to the path.
  • OPTION 2: Update Python3 and pip3 if there are versions already installed on your device:
    • Add the following to the command line:

sh

1python -m pip install --upgrade pip

2. Run a sample

You'll download and run the OfficeToPDFTest sample which allows you to explore and validate the conversion feature offered by the SDK. By running the sample, you can quickly:

  • Verify the capabilities.
  • Understand how to interact with the MS Office to Conversion PDF API.
  • Use it as a reference for integrating similar functionality into your own application.
  1. Download the zip file for Windows which includes all of the Apryse samples.
  2. Select Documents, New Folder, then enter ApryseSamples, and press Enter to create a new folder to extract the zip file into for running the samples. You can create a folder at a different location if you prefer, but for this guide’s instructions, we used the location and name above.
  3. Use your Windows file explorer to navigate to the Downloads folder, right-click on the zip file, then select Extract all.
  4. Click Browse.
  5. Go to the new folder you made, highlight it, then click Select Folder.
  6. Click Extract.

The file is extracted to the folder.

7. Navigate to the folder /Documents/ApryseSamples/Samples/OfficeToPDFTest/Python, right-click on the Python folder, then select Open in Terminal.

8. The Windows terminal opens to the directory you specified. On the command line, enter the following, then press Enter to install the apryse-sdk library from Apryse’s S3 private repository (You need this to run samples successfully):

We recommend running this in a virtual environment, to guarantee the location of where our library will be installed. Henceforth, if our library needs to be imported, be sure to activate the same virtual environment before running a Python script that imports from apryse-sdk.

The PDFNetPython3 library from the default Python Package Index (PyPI) is not used in the code below because it’s no longer being updated. You’ll use the Apryse PyPI instead in the code.

sh

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

If no errors occur, Successfully installed apryse-sdk... will display in terminal.

9. Navigate via your Windows file explorer to /Documents/ApryseSamples/Samples/LicenseKey/Python/LicenseKey.py and double-click to open so you can add your license key to the LicenseKey.py file before running the sample.

10. Scroll down to the line containing ‘LicenseKey = “YOUR_PDFTRON_LICENSE_KEY”' and replace the words in quotes with the copy of your trial license key. Leave the ‘if LicenseKey ==YOUR_PDFTRON_LICENSE_KEY’ as is with its default text.

11. Save your changes and close the file.

12. To run the sample, navigate, through the Windows file explorer, to the folder you created:  /Home/ApryseSamples/Samples/OfficeToPDFTest/Python, right-click on the Python folder, then select Open in Terminal.

13. The Windows terminal opens the OfficeToPDFTest sample. From the project directory, on the command line, enter the following, then press Enter:

sh

1python –u OfficeToPDFTest.py

When you run the command, the sample code loads an Office document, converts the Office document to PDF, saves the resulting PDF, and outputs status messages to the console. For more details, you can look at additional OfficeToPDFsample code and the Convert MS Office (Word, Excel, PowerPoint) to PDF overview.

Once the sample finishes running, you'll see the status Done in the terminal.

14. At the command prompt, type exit, then press Enter.

15. Go to your Windows file explorer and navigate to: /Documents/ApryseSamples/Samples/TestFiles/Output. You will see three output PDF files (Fisherman.pdf, the_rime_of_the_ancient_mariner.pdf, and the factsheet_Arabic.pdf):

16. Open the PDF files to see the converted output. You have successfully run the OfficeToPDFTest conversion sample!

3. Create a new project

Next, you’ll create your own Python3 project and add the Apryse Server SDK so you can later integrate the Apryse Server SDK into the project and run it.

  1. In your Windows file explorer, navigate to the Documents folder, and add a new folder.
  2. Enter the folder name, NewApryseProject, then press Enter.

4. Integrate the Apryse Server SDK into your application

Next, you’ll open a blank PDF page within your application.

  1. Open Visual Studio Code (or your preferred application) and from the File menu, select Open Folder.
  2. Navigate to the Documents folder from Windows file explorer, then, select the NewApryseProject folder and click Select Folder.

The NewApryseProject opens in Visual Studio Code.

3. Create a file in the project named HelloWorld.py.

4. Copy the following Python code and paste it into Line 1 of the HelloWorld.py file, then Save your file:

Python

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 # You need to initialize the PDFNet library
10 # Before calling any PDF related methods
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 # We 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(("linearized_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()

Keep in mind the following about the code above:

  • You’re importing the Apryse SDK.
  • You’re initializing PDFNet using your Apryse license key. Scroll down to the line containing PDFNet.Initialize(“YOUR_LICENSE_KEY”); and replace the words in quotes with the copy of your trial license key. If you’re logged in to Apryse.com, your license key will automatically replace YOUR_LICENSE_KEY in the code above.
  • You’re doing various work with PDFNet. In this case, with a PDFDoc object.
  • You’re calling PDF.Terminate which releases any resources in use.

5. To test that your code works, run the script in the folder containing HelloWorld.py in the command prompt, then press Enter.

sh

1python.exe -u HelloWorld.py

6. The code executes and you will see “PDFNet is running in demo mode.”

7. Exit out of the command line and navigate to the Documents > NewApryseProject folder from Windows file explorer.

8. Open the linearized_output.pdf which you created by integrating the Apryse Server SDK!

9. Now that you have successfully run an OfficeToPDFTest sample and integrated the Apryse Server SDK Python PDF Library into your application, you can try out 50+ samples depending on your needs.

10. To try additional samples, go to section 2. Run a sample > Step 7 above and choose a different sample to run with a different URL path.

Additional modules are required for some samples functionality, For example, OCR, CAD and PDF to Office. You can get these from our additional module downloads page.


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