Some test text!

Loading...
Guides

Get started with Python3

Welcome to PDFTron. Python3 for the PDFTron SDK is supported on both Linux and Windows and requires that custom wrappers are built. To get started, choose your preferred platform from the tabs below.

macOS Python custom wrapper PDF library integration

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

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

Prerequisites

  • Python 3.5 - 3.10 for x64

    Python 3.9 - 3.10 for Apple M1 (ARM processor)

  • pip3

    Make sure python3 and pip3 are installed in your system. You can check your python version and pip3 version by using the command in terminal:

python3 --version
python3 -m pip --version

You can install python3 and pip3 with Homebrew using the following command:

brew install python3

There are THREE steps needed before you can use PDFNetPython3 library.

Step 1

Use pip3 to install PDFNetPython3 library from Python Package Index (PyPI) in terminal.

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 PDFNetPython3

python3 -m pip install PDFNetPython3

or

pip3 install PDFNetPython3

If no errors occur, Successfully installed PDFNetPython3 ... will display in terminal.

If you run into this error when installing PDFNetPython3 via pip:

ERROR: Could not find a version that satisfies the requirement PDFNetPython3 (from versions: none)
ERROR: No matching distribution found for PDFNetPython3

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

python3 --version

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

Step 2

Download PDFNetPython3 Samples and unzip the package.

Step 3

Get your PDFTron trial key.

Login/Sign Up to your account to get access to key

Run the Samples

Navigate to the PDFNetPython3/Samples folder. Notice that you will need to update PDFNetPython3/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.sh and use the following commands to run it in terminal:

cd PDFNetPython3/Samples/AddImageTest/PYTHON
sh RunTest.sh

Alternatively, you can use the following commands to run AddImageTest:

cd PDFNetPython3/Samples/AddImageTest/PYTHON
python3 -u AddImageTest.py

If no errors occur, the following lines will display in terminal:

PDFNet is running in demo mode.
Permission: write
Done. Result saved in addimage.pdf...

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

Run all samples

  1. Find runall_python.sh in the samples folder and run it.
cd PDFNetPython3/Samples
sh runall_python.sh

The output files from all tests are stored in Samples/TestFiles/output/.

Integrate into your application

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

Below is an example called HelloWorld.py:

# You can add the following line to integrate PDFNetPython3
# into your solution from anywhere on your system so long as
# the library was installed successfully via pip

from PDFNetPython3 import *

def main():

    # You need to initialize the PDFNet library 
    # Before calling any PDF related methods
    PDFNet.Initialize()

    # This example creates a new document
    # and a new page, then adds the page
    # in the page sequence of the document
    doc = PDFDoc()

    page1 = doc.PageCreate()
    doc.pagePushBack(page1)

    # We save the document in a linearized
    # format which is the most popular and 
    # effective way to speed up viewing PDFs
    doc.Save(("linearized_output.pdf"), SDFDoc.e_linearized)

    doc.close()

if __name__ == "__main__":
    main()

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

python3 -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 downloaded here .

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

Guides Samples

Troubleshooting

  1. If you run into this error when installing PDFNetPython3 via pip:
ERROR: Could not find a version that satisfies the requirement PDFNetPython3 (from versions: none)
ERROR: No matching distribution found for PDFNetPython3

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

python3 --version

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

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 PDFNetPython3 library via pip, you need to check whether python3 and pip3 are installed in your system.

    You can test it by using the following command:

    python3 -m pip --version

    If no errors occur and your python version is within 3.5 - 3.10, it may be that no precompiled PDFNetPython3 library is compatible with your system. Please contact our support team. You might need to build your own PDFNetPython3 wrapper using SWIG and our PDFNetC library.

  2. 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 PDFNetPython3, as follows:

# Creates a venv/ folder in your current directory
python3 -m venv venv
# Activate the virtual environment in the current terminal session
source venv/bin/activate
  1. If you want to upgrade PDFNetPython3 to the latest version, you can simply run:

    python3 -m pip install PDFNetPython3 --upgrade
  2. If you run a sample and get the output:

nopip You will need to install PDFNetPython3 via pip first before you could run the sample.

Get the answers you need: Support

Upcoming Webinar: PDFTron SDK Tech Review | Nov 29, 2022 at 2 pm ET

PDFTron SDK

The Platform

NEW

© 2022 PDFTron Systems Inc. All rights reserved.

Privacy

Terms of Use