Custom Python wrapper for PDF library integration
There are two ways to use Apryse with Python:
Use pip - the precompiled library for Python 3.x.
(less common) Use PDFNet bindings to build your own wrappers.
This guide will help you get started by building your own wrapper. You can find more information about using the precompiled library
Custom Python wrapper & macOS PDF library integration
This guide will help you run Apryse samples and integrate a free trial of the Apryse SDK into Python applications on macOS. Your free trial includes unlimited trial usage and support from solution engineers.
Prerequisites
Python3 or Python2 with developer extensions
CMake version ≥ 2.8
SWIG 2.0.4 - 2.0.12 or SWIG 3.0.12 or SWIG 4.0.2 and above
Apryse's Python3 PDF library for macOS:
curl -L -O https://downloads.apryse.com/downloads/PDFNetCMac.zip
unzip PDFNetCMac.zipInitial setup
Make a directory to store the wrappers and navigate into that directory.
Clone the PDFNet Wrappers project, select the correct branch for your release afterwards. This is typically a numbered release such as
11.11,11.12,11.13and12.0.
Navigate to
PDFNetWrappers/PDFNetCand move the downloaded [PDFNet C/C++ SDK] for macOS(#prerequisites) into that directory and unzip it. Ensure you obtain the right architecture for your Python interpreter. This can be done with these two commands:
Now to move the headers in place, make sure you are in the
PDFNetWrappers/PDFNetCdirectory and executeandto move the PDFNet libraries in place.You can deletePDFNetCMac.zipto free up space.Your/PDFNetCfolder should be laid out like this like this:
Make a build directory inside
/PDFNetWrappersand navigate to it. This guide will assume the build directory is called Build.ExecuteIf all goes well, you should get a message which reads:
Execute
makefollowed bysudo make install.Next we need to fix the
rpathsissue on Mac. While still in the sameBuilddirectory, execute these lines:
Get your Apryse trial key.
You are now ready to run the samples or integrate Apryse SDK into your own application.
Run the samples
Running a specific sample
Navigate to the
PYTHONfolder in the sample, for example/Samples/AddImageTest/PYTHONand execute./RunTest.sh.
Run all samples
To run all tests, navigate to
/Samplesand executeThe tests will run one by one.
Integrate into your application
This section will show you how to use our SDK to create a simple Apryse "Hello World!" application. It will create a document with one blank page and save it as a linearized PDF in its running directory.
Navigate to the
/Samplesdirectory and create a new directory calledmyApp(if it does not exist already). This guide will assume your application is named myApp. For organization, create a new directory insidemyAppcalledPYTHON.Navigate inside that
PYTHONdirectory and create a new Python file calledmyApp.py. Open it with your favorite text editor and paste this into it:
Run your application via
python myApp.py. If all goes well your output should read:
Check the output.pdf that the program output in the same directory. It should be a PDF with one blank page.
Next step
Troubleshooting
Check the troubleshooting page and our PDFNetWrappers github if you run into any issues going through this document.
Custom Python wrapper & 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.
Prerequisites
Python 2.7 or 3.x.Make sure the executable name is
python.exeClone the PDFNet Wrappers project, select the correct branch for your release afterwards. This is typically a numbered release such as
11.11,11.12,11.13and12.0.
Apryse's Python PDF library for Windows:
Make sure Python, cmake and SWIG are all added to your path environment variable.
Initial setup
Extract the
PDFNetWrappersWinXXfolder from the .zip file. This guide will assume it has been extracted to the current user'sDesktop.From the extracted folder, copy the
LibandHeadersfolders and paste them intoPDFNetWrappers-master/PDFNetC/Create a new folder called
Buildinside thePDFNetWrappersfolder and enter it.This is what the current directory structure should look like:

Open a Command Prompt here and run the following:
This will choose a default Visual Studio version to build the projects for. Wait for the bindings to finish. The output should end with something like this:
If you see error messages during this process, see the Troubleshooting section.You should have the following files in your Build directory:

Open the generated
PDFNetLanguageBindings.slnwith Visual Studio.Change the build mode from
DebugtoRelease, make sure the appropriate target version (x86 or x64) is selected and build the solution.
When using the
PDFNetC64(64-bit) library files then change the build configuration tox64in theBuilddropdown by choosingConfiguration Manager....UnderActive Solution Platform, Select<New...>and choosex64ifx64is not displayed as a platform.Click ok then close the modal to exit.Right-click project
PDFNetPythonwithin Solution Explorer and chooseProperties.UnderLinker, selectCommand Lineand changeX86toX64.Click ok to exit the modal.Right-click and build the
PDFNetPythonproject.This will build the Python library files.Copy the
_PDFNetPython.pyddynamic link library file to thebuild\lib\Releasefolder using the command line below or manually from Windows explorer.This will ensure the Python module which communicates through the dynamic link library can be located for installation.
When this is done, select and build the
INSTALLproject.This will installPDFNetPythonlib files to thePDFNetWrappers\PDFNetC\libfolder where it can be located by the samples.Get your Apryse trial key.
The bindings should be successfully built. You can now run the samples to test out the Apryse SDK.
Run the samples
Find and enter the Samples folder (PDFNetWrappers-master/Samples). Here you can find sample code for a large number of features supported by the Apryse SDK.
The output files from all tests are stored in Samples/TestFiles/output/
Run a specific sample
Find the sample you want to run and navigate into the
PYTHONfolder inside.Find
RunTest.batand run it. The results should appear on acmdwindow.

Run all samples
Find
runall_python.batin the samples folder and double click on it to run it. The results should appear on acmdwindow.
Press any key when a sample ends to start the next one.

Integrate into your application
This is what we call the "Apryse Hello World" application. It is easy to integrate the rest of Apryse SDK if you are able to open, save and close a PDFDoc.
Create a new folder in
Samplesby the nameHelloWorld.In the
HelloWorldfolder, create a new file calledHelloWorld.py, open and edit it using your favorite text editor.Insert the following to your file:To test that your code works, run the code using a shell in the
HelloWorldfolder using:Once you have successfully run this, you should see an output file in the working directory of this program.
Next step
Troubleshooting
Multiple versions of Python More information for conflict resolution between multiple Python installations.
CMake Process finding incorrect version Setting specific versions of Python to use for cmake.
Custom Python wrapper & Linux PDF library integration
This guide will help you run Apryse samples and integrate a free trial of the Apryse SDK into Python applications on Linux. Your free trial includes unlimited trial usage and support from solution engineers.
Prerequisites
Python3 or Python2 with developer extensions
CMake version ≥ 2.8
SWIG 2.0.4 - 2.0.12 or SWIG 3.0.12 or SWIG 4.0.2 and above
Apryse SDK for Linux:
Initial setup
Make a directory to store the wrappers and navigate into that directory.
Clone the PDFNet Wrappers project, select the correct branch for your release afterwards. This is typically a numbered release such as
11.11,11.12,11.13and12.0.
Navigate to
PDFNetWrappers/PDFNetCand download the PDFNet C/C++ SDK into that directory. Ensure you obtain the right architecture for your Python interpreter. For example, if your interpreter is 64bit (which this guide will assume), execute
Unpack
PDFNetC64.tar.gzbytar xvzf PDFNetC64.tar.gz, then executeandto move the PDFNet libraries in place.You can deletePDFNetC64.tar.gzto free up space.Your/PDFNetCfolder should be laid out like this like this:
Make a build directory inside
/PDFNetWrappersand navigate to it. This guide will assume the build directory is called Build.ExecuteIf all goes well, you should get a message which reads:
Execute
makefollowed bysudo make install. You are now ready to run the samples or integrate Apryse SDK into your own application.
Get your Apryse trial key.
Run the samples
Running a specific sample
Navigate to the
PYTHONfolder in the sample, for example/Samples/AddImageTest/PYTHONand execute./RunTest.sh.
Run all samples
To run all tests, navigate to
/Samplesand executeThe tests will run one by one.
Integrate into your application
This section will show you how to use our SDK to create a simple Apryse "Hello World!" application. It will create a document with one blank page and save it as a linearized PDF in its running directory.
Navigate to the
/Samplesdirectory and create a new directory calledmyApp(if it does not exist already). This guide will assume your application is named myApp. For organization, create a new directory insidemyAppcalledPYTHON.Navigate inside that
PYTHONdirectory and create a new Python file calledmyApp.py. Open it with your favorite text editor and paste this into it:
Run your application via
python myApp.py. If all goes well your output should read:
Check the output.pdf that the program output in the same directory. It should be a PDF with one blank page.
Next step
Troubleshooting
Check the troubleshooting page and our PDFNetWrappers github if you run into any issues going through this document.
Last updated
Was this helpful?