Some test text!
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.
There are two ways to use PDFTron with Python:
This guide will help you get started by building your own wrapper. You can find more information about using the precompiled library .
Make sure the executable name is
Download the PDFNet Wrapper files or clone the repository:
git clone https://github.com/PDFTron/PDFNetWrappers.git
If you downloaded, extract the PDFNetWrappers-master folder.
PDFTron's Python PDF library for Windows:
Make sure Python, cmake and SWIG are all added to your
path environment variable.
PDFNetWrappersWinXX folder from the .zip file. This guide will assume it has been extracted to the current user's
From the extracted folder, copy the
Headers folders and paste them into
Create a new folder called
Build inside the
PDFNetWrappers folder and enter it.
This is what the current directory structure should look like:
Open a Command Prompt here and run the following:
cmake -D BUILD_PDFNetPython=ON ..
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:
-- Build files have been written to: C:/Users/User_Name/Desktop/PDFNetWrappers-master/Build
If you see error messages during this process, see the Troubleshooting section.
You should have the following files in your
Open the generated
PDFNetLanguageBindings.sln with Visual Studio.
Change the build mode from
Release, 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 to
x64 in the
Build dropdown by choosing
Active Solution Platform, Select
<New...> and choose
x64 is not displayed as a platform.
Click ok then close the modal to exit.
PDFNetPython within Solution Explorer and choose
Command Line and change
Click ok to exit the modal.
Right-click and build the
This will build the Python library files.
_PDFNetPython.pyd dynamic link library file to the
build\lib\Release folder 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.
copy ".\x64\Release\_PDFNetPython.pyd" ".\lib\Release"
When this is done, select and build the
This will install
PDFNetPython lib files to the
PDFNetWrappers\PDFNetC\lib folder where it can be located by the samples.
Get your PDFTron trial key.
The bindings should be successfully built. You can now run the samples to test out the PDFTron SDK.
Find and enter the
Samples folder (
PDFNetWrappers-master/Samples). Here you can find sample code for a large number of features supported by the PDFTron SDK.
The output files from all tests are stored in
Run a specific sample
Find the sample you want to run and navigate into the
PYTHON folder inside.
RunTest.bat and run it. The results should appear on a
Run all samples
runall_python.batin the samples folder and double click on it to run it. The results should appear on a
Press any key when a sample ends to start the next one.
This is what we call the "PDFTron Hello World" application. It is easy to integrate the rest of PDFTron SDK if you are able to open, save and close a PDFDoc.
Create a new folder in
Samples by the name
HelloWorld folder, create a new file called
HelloWorld.py, open and edit it using your favorite text editor.
Insert the following to your file:
# You can use the following two lines to use PDFNetPython # in your solution from anywhere on your system # so long as you have relative path import site site.addsitedir("../../Lib") import sys # This is the most important packages to import # for basic document manipulation. from PDFNetPython 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 code using a shell in the
HelloWorld folder using:
python.exe -u HelloWorld.py
Once you have successfully run this, you should see an output file in the working directory of this program.
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.
Get the answers you need: Support