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

1python3 --version
2python3 -m pip --version

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

sh

1brew install python3
  • OPTION 2: Update Python3 and pip3, through Homebrew, if there are versions already installed on your device:
    • Add the following to the command line to ensure Homebrew is up to date:

sh

1brew update
  • Add the following to the command line:

sh

1brew upgrade python3

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 macOS which includes all of the Apryse samples.
  2. Go to your Downloads folder and double-click the file to unzip it.
  3. Select Documents, File > New Folder to add a new folder, then enter ApryseSamples as the folder name, and press Enter to create the new folder. 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.
  4. Use your Mac Finder to navigate to the Downloads folder, copy the unzipped folder, and paste it into the new folder you made, ApryseSamples.
  5. Navigate to the folder  /Documents/ApryseSamples/PDFNetPython3/Samples/OfficeToPDFTest/Python, right-click on the Python folder, then select New Terminal at Folder.
  6. The macOS 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 your library will be installed. Henceforth, if your 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

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

or

sh

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

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

7. Navigate via your Mac Finder to /Documents/ApryseSamples/PDFNetPython3/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.

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

9. Save your changes and close the file.

10. To run the sample, navigate, through the Mac Finder, to the folder you created:  /Home/ApryseSamples/PDFNetPython3/Samples/OfficeToPDFTest/Python, right-click on the Python folder, then select New Terminal at Folder.

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

sh

1sh RunTest.sh

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.

12. At the command prompt, type Exit, then press Enter.

13. Go to your Mac Finder 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):

14. 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 Mac Finder, 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 the Mac Finder, 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("demo:1763580498695:601269ef03000000007505554501519c80287620321ec3184e959426e1")
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(("linearized_output.pdf"), SDFDoc.e_linearized)
25
26 doc.Close()
27
28if __name__ == "__main__":
29 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.

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

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