Python 3.x PDF library integration

Welcome to Apryse. Python 3.x for the Apryse SDK is cross-platform and supported on Windows, Linux and macOS.

There are three ways to use Apryse with Python:

This guide will help you get started using the precompiled Python wrappers for 3.x. To get started, choose your preferred platform from the tabs below.

Precompiled Python3 & Windows PDF library integration

This guide will help you run Apryse samples and integrate a free trial of the Apryse SDK into Python applications on Windows. Your free trial includes unlimited trial usage and support from solution engineers.

Run Apryse SDK in production

A commercial license key is required for use in a production environment. Please contact sales to purchase a commercial key or if you need any other license key assistance.

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

Prerequisites

  • Python 3.5 - 3.12 and pip.Make sure the executable name is python.exe (default on Windows) and Python is added to your path environment variable.

There are THREE steps needed before you can use apryse-sdk library.

Step 1

Use pip to install apryse-sdk library from Apryse's S3 private repository in terminal. Notice that PDFNetPython3 library from Python Package Index (PyPI) will no longer be updated in the future after the 9.5.0 release.

sh

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

or

sh

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

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

If you run into this error when installing apryse-sdk via pip:

sh

1ERROR: Could not find a version that satisfies the requirement apryse-sdk (from versions: none)
2ERROR: No matching distribution found for apryse-sdk

It is possible that your Python version is NOT fully compatible. You can check your python version by using the command:

sh

1python --version

and make sure your Python version is within 3.5 - 3.11.

Step 2

Download apryse-sdk Samples and unzip the package.

Step 3

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 the Samples

Navigate to the Samples folder. Notice that you will need to update Samples/LicenseKey/PYTHON/LicenseKey.py before you could run Samples.

Run a specific sample

  1. Find the sample you want to run and navigate into the PYTHON folder inside.
  2. Find RunTest.bat and double click on it to run it. Alternatively, you can use the following command to run AddImageTest in command prompt:

sh

1cd Samples\AddImageTest\PYTHON
2python -u AddImageTest.py

Apryse Docs Image

The output files are stored in Samples/TestFiles/output/

Run all samples

Find runall_python.bat in the samples folder and double click on it to run it. The output files from all tests are stored in Samples/TestFiles/output/.

Integrate into your application

It is easy to integrate apryse-sdk into your application. After you have installed apryse-sdk via pip, all you need to do is add from apryse-sdk import * to your Python script.

Below is an example called HelloWorld.py:

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_APRYSE_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(("linearized_output.pdf"), SDFDoc.e_linearized)
25
26 doc.Close()
27
28if __name__ == "__main__":
29 main()

To test that your code works, run the script in the folder containing HelloWorld.py in command prompt:

sh

1python.exe -u HelloWorld.py

Once you have successfully run this, you should see an output file in the working directory of this program.

Installing Additional Modules

Additional modules are required to run our OCRTest or CADTest samples, which can be accessed on our additional module downloads page.

Be sure to merge the Samples/ directory from the module into the Samples/ directory obtained from the download in Step 2, ensuring that the files the sample code depends on are available.

Next step

Troubleshooting

  1. If you run into this error when installing apryse-sdk via pip:

sh

1ERROR: Could not find a version that satisfies the requirement apryse-sdk (from versions: none)
2ERROR: No matching distribution found for apryse-sdk

It is possible that your Python version is NOT fully compatible. You can check your python version by using the command:

sh

1python --version

and make sure your Python version is within 3.5 - 3.11.

We recommend using Python 3.5.4, 3.6.8, 3.7.9, 3.8.5, 3.9.6, 3.10.4 to guarantee 100% compatibility.

If errors still occur, please contact our support team.

  1. If you cannot install apryse-sdk library via pip, you need to check whether python and pip are installed in your system.You can test it by using the following command:If no errors occur and your python version is within 3.5 - 3.11, it may be that no precompiled apryse-sdk library is compatible with your system. Please contact our support team. You might need to build your own apryse-sdk wrapper using SWIG and our PDFNetC library.

sh

1python -m pip --version
  1. If you are running into issues with compatibility with other libraries, we recommend using our library 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, as follows:

sh

1# Creates a venv/ folder in your current directory
2python -m venv venv
3# Activate the virtual environment in the current command prompt session
4venv\Scripts\activate.bat
  1. If you want to upgrade apryse-sdk to the latest version, you can simply run:

sh

1python -m pip install apryse-sdk --upgrade --extra-index-url=https://pypi.apryse.com
  1. If you run a sample and get the output: You will need to install apryse-sdk via pip first before you could run the sample.
Apryse Docs Image

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales