Foxit PDF SDK for Linux Foxit PDF SDK for Mac Foxit PDF SDK for Windows

Developer Guide for Foxit PDF SDK for Python (9.0)

Introduction to Foxit PDF SDK

Have you ever thought about building your own application that can do everything you want with PDF files? If your answer is “Yes”, congratulations! You just found the best solution in the industry that allows you to build stable, secure, efficient and full-featured PDF applications.

Foxit PDF SDK provides high-performance libraries to help any software developer add robust PDF functionality to their enterprise, mobile and cloud applications across all platforms (includes Windows, Mac, Linux, Web, Android, iOS, and UWP), using the most popular development languages and environments.

Why Choose Foxit PDF SDK

Foxit is a leading software provider of solutions for reading, editing, creating, organizing, and securing PDF documents. Foxit PDF SDK libraries have been used in many of today’s leading apps, and are proven, robust, and battle-tested to provide the quality, performance, and features that the industry’s largest apps demand. Customers choose Foxit PDF SDK product for the following reasons:

Easy to integrate

Developers can seamlessly integrate Foxit PDF SDK into their own applications.

Lightweight footprint

Does not exhaust system resource and deploys quickly.

Cross-platform support

Support current mainstream platforms, such as Windows, Mac, Linux, Web, Android, iOS, and UWP.

Powered by Foxit’s high fidelity rendering PDF engine

The core technology of the SDK is based on Foxit’s PDF engine, which is trusted by a large number of the world’s largest and well-known companies. Foxit’s powerful engine makes the app fast on parsing, rendering, and makes document viewing consistent on a variety of devices.

Premium World-side Support

Foxit offers premium support for its developer products because when you are developing mission critical products you need the best support. Foxit has one of the PDF industry’s largest team of support engineers. Updates are released on a regular basis to improve user experience by adding new features and enhancements.

Foxit PDF SDK for Python API

Application developers who use Foxit PDF SDK can leverage Foxit’s powerful, standard-compliant PDF technology to securely display, create, edit, annotate, format, organize, print, share, secure, search documents as well as to fill PDF forms. Additionally, Foxit PDF SDK (for Python) includes a built-in, embeddable PDF Viewer, making the development process easier and faster. For more detailed information, please visit the website https://developers.foxitsoftware.com/pdf-sdk/.

In this guide, we focus on the introduction of Foxit PDF SDK for Python API on Windows, Linux and Mac platforms.

Foxit PDF SDK for Python API ships with simple-to-use APIs that can help Python developers seamlessly integrate powerful PDF technology into their own projects on Windows, Linux and Mac platforms. It provides rich features on PDF documents, such as PDF viewing, bookmark navigating, text selecting/copying/searching, PDF signatures, PDF forms, rights management, PDF annotations, and full text search.

Evaluation

Foxit PDF SDK allows users to download a trial version to evaluate the SDK. The trial version has no difference from a standard version except for the 10-day limitation trial period and the trail watermarks that will be generated on the PDF pages. After the evaluation period expires, customers should contact Foxit sales team and purchase licenses to continue using Foxit PDF SDK.

License

Developers should purchase licenses to use Foxit PDF SDK in their solutions. Licenses grant users permissions to release their applications based on PDF SDK libraries. However, users are prohibited to distribute any documents, sample codes, or source codes in the SDK released package to any third party without the permission from Foxit Software Incorporated.

About this guide

This guide is intended for developers who need to integrate Foxit PDF SDK for Python API into their own applications. It aims at introducing the installation package, and the usage of SDK.


Getting Started

It’s very easy to setup Foxit PDF SDK and see it in action! This guide will provide you with a brief introduction about our SDK package. As a cross-platform product, Foxit PDF SDK supports the identical interfaces for desktop system of Windows, Linux, and Mac. The following sections introduce the contents of system requirements, the installation package as well as how to run a demo, and create your own project.

System Requirements

Platform System Requirement Note
Windows Windows Vista, 7, 8 and 10 (32-bit and 64-bit) Windows Server 2003, 2008 and 2012 (32-bit and 64-bit) It only supports for Windows 8/10 classic style, but not for Store App or Universal App.
Linux x86/x64 (32-bit and 64-bit OS) Starting from version 8.4 Foxit PDF SDK for Linux (x86 and x64), the minimum supported version of GCC compiler has been upgraded from gcc4.8 to gcc4.9.4. All Linux for x86/x64 samples have been tested on Ubuntu16.0 32/64 bit.
Mac Mac OS X 10.9 or higher (64-bit OS) Mac OSX 11.2 or higher (arm64) It supports macOS x64 and arm64.

Windows

In this guide, the highlighted rectangle in the figure is the version of the SDK. Here the SDK version is 9.0, so it shows 9_0.

What is in the package

Download the Foxit PDF SDK zip for Windows package and extract it to a new directory “foxitpdfsdk_9_0_win_python”, which is shown in Figure 2-1. The release package contains the following folders:

doc: developer guide

examples: sample projects and demos

FoxitPDFSDKPython2: libraries of the python2.7

res: the default icc profile files used for output preview demo

Figure 2-1

How to run a demo

Currently, we only release the windows version based on python 2.7 and python 3.6-3.10. Please contact us if other versions are required.

Requirement

Python 2.7 or 3.6-3.10, a single version of Python installed on the system is allowed.

Make sure your default command is python.exe, and it is added in your system path environment variables.

Python 3.6-3.10 use pip to install FoxitPDFSDKPython3 module from pypi.

> pip install FoxitPDFSDKPython3

Install third party modules using pip.

> pip install cryptography

> pip install pyOpenSSL

> pip install uuid

About package directory structure

The folder FoxitPDFSDKPython2 is used for python2.7. If you use python2.7 32bit, you need to manually copy from FoxitPDFSDKPython2/x86_vc15/_fsdk.pyd to FoxitPDFSDKPython2/. If you use python2.7 64bit, you need to manually copy from FoxitPDFSDKPython2/x64_vc15/_fsdk.pyd to FoxitPDFSDKPython2/. You can also run examples/rundemo_python.py for automatic copying.

How to run the examples

Use rundemo_python.py to run the examples on Python

This command will run all examples.

> cd examples/simple_demo/

> python rundemo_python.py

This command will run a single example annotation.

> cd examples/simple_demo/

> python rundemo_python.py annotation

Run the examples script directly with python.

For Python2.7, if _fsdk.pyd in the corresponding directory matches the current system python version, you can use python to run the examples directly. For the correspondence between _fsdk.pyd and python version, please see About package directory structure. For Python3, if you have installed FoxitPDFSDKPython3 module, you can use python to run the examples directly.

This command will run a single example annotation.

> cd examples/simple_demo/annotation/

> python -u annotation.py

Security demo

Before running security demo, you should install the certificates “foxit.cer” and “foxit_all.pfx” found in “\examples\simple_demo\input_files” folder.

To install “foxit.cer”, double-click it to start the certificate import wizard. Then select “Install certificate… > Next > Next > Finish”.

To install “foxit_all.pfx”, double-click it to start the certificate import wizard. Then select “Next > Next > (Type the password “123456” for the private key in the textbox) and click Next > Next > Finish”.

Run the demo following the steps as the other demos.

Signature demo and Paging_seal_signature demos

Before running signature and paging_seal_signature demos, you should ensure that the cryptography and pyopenssl has been already installed in your machine.

OCR and Compliance demos

For ocr and compliance demos, you should build a resource directory at first, please contact Foxit support team or sales team to get the resource files packages. For more details about how to run the demos, please refer to section 3.34 “OCR” and section 3.35 “Compliance”.

HTML to PDF demo

For html2pdf demo, you should contact Foxit support team or sales team to get the engine files package for converting from HTML to PDF at first. For more details about how to run the demo, please refer to section 3.37 “HTML to PDF Conversion”.

Office to PDF demo

For office2pdf demo, you should make sure that Microsoft Office 2007 version or higher is already installed and the default Microsoft virtual printer is already set on your Windows system. Then, run the demo following the steps as the other demos.

Output Preview demo

For output preview demo, you should set the folder path which contains default icc profile files. For more details about how to run the demo, please refer to section 3.39 “Output Preview”.

PDF to Office demo

For pdf2office demo, you should contact Foxit support team or sales team to get the engine files package for converting from PDF to office at first. For more details about how to run the demo, please refer to section 3.44 “PDF to Office Conversion”.

How to create a simple project

In this section, we will show you how to use Foxit PDF SDK for Windows Python to create a simple project that renders the first page of a PDF to a bitmap and saves it as a JPG image. Please follow the steps below:

Create a new project folder named “test_win”.

Copy the ” SamplePDF.pdf” from the “foxitpdfsdk_9_0_win_python/example/simple_demo/input_files” to the folder “test_win”.

For Python2, copy the folder “FoxitPDFSDKPython2” from the folder “foxitpdfsdk_9_0_win_python” to the folder “test_win”. For Python3, run the command as ” pip install FoxitPDFSDKPython3″ to install the package from pypi.

Add the following Python script file “test_win.py” to the folder “test_win”.

Set the value of “sn” in test_linux.py with the string after “SN=” from “gsdk_sn.txt”.

Set the value of “key” in test_linux.py with the string after “Sign=” from “gsdk_key.txt”.

import sys

import site

import platform

from shutil import copyfile

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

# For Python2, copy the corresponding version of the dynamic library to the folder FoxitPDFSDKPython2.

if _PYTHON2_:

arch = platform.architecture()

if arch[0] == 32bit“:

src_lib_path = ./FoxitPDFSDKPython2/x86_vc15/_fsdk.pyd

elif arch[0] == 64bit“:

src_lib_path = ./FoxitPDFSDKPython2/x64_vc15/_fsdk.pyd

dest_lib_path = ./FoxitPDFSDKPython2/_fsdk.pyd

if src_lib_path is not None:

copyfile(src_lib_path, dest_lib_path)

if _PYTHON2_:

site.addsitedir(‘./‘)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Assuming PDFDoc doc has been loaded.

# The value of “sn” can be got from “gsdk_sn.txt” (the string after “SN=”).

# The value of “key” can be got from “gsdk_key.txt” (the string after “Sign=”).

sn =

key =

def main():

# Load a PDF document, and parse the first page of the document.

doc = PDFDoc(“SamplePDF.pdf“)

error_code = doc.Load(“”)

if error_code!= e_ErrSuccess:

return 0

page = doc.GetPage(0)

page.StartParse(PDFPage.e_ParsePageNormal, None, False)

width = int(page.GetWidth())

height = int(page.GetHeight())

matrix = page.GetDisplayMatrix(0, 0, width, height, page.GetRotation())

# Prepare a bitmap for rendering.

bitmap = Bitmap(width, height, Bitmap.e_DIBArgb)

bitmap.FillRect(0xFFFFFFFF, None)

# Render page.

render = Renderer(bitmap, False)

render.StartRender(page, matrix, None)

# Add the bitmap to image and save the image.

img = Image()

img.AddFrame(bitmap)

img.SaveAs(“testpage.jpg“)

return 0

if __name__ == __main__‘:

code = Library.Initialize(sn, key)

if code == e_ErrSuccess:

main()

Library.Release()

Run “test_win.py” on the CMD as “python test_win.py”, and the “testpage.jpg” will be generated in current folder.

Linux

In this guide, the highlighted rectangle in the figure is the version of the SDK. Here the SDK version is 9.0, so it shows 9_0.

What is in the package

Download the Foxit PDF SDK zip for Linux (x86/x64) Python package and extract it to a new directory “foxitpdfsdk_9_0_linux_python”. The structure of the release package is shown in Figure 2-2. This package contains the following folders:

doc: developer guide

examples: sample projects and demos

FoxitPDFSDKPython2: libraries of the python2.7

res: the default icc profile files used for output preview demo

Figure 2-2

How to run a demo

GCC compiler update on Linux

Starting from version 8.4 Foxit PDF SDK for Linux (x86 and x64), the minimum supported version of GCC compiler has been upgraded from gcc4.8 to gcc4.9.4. For the SDK to work properly, make sure your current GCC version is 4.9.4 or higher, or the libstdc++.so.6 is 6.0.20 or higher.

Requirement

Python 2.7 or 3.6-3.10, a single version of Python installed on the system is allowed.

Make sure that the default command is python and it is added in the system path environment variables.

Python 3.6-3.10 use pip to install FoxitPDFSDKPython3 module from pypi.

$ pip install FoxitPDFSDKPython3

Install third party modules using pip.

$ pip install cryptography==2.3

$ pip install pyopenssl==19.0.0

$ pip install uuid

About the package directory structure

The folder FoxitPDFSDKPython2 is used for python2.7. If you use python2.7 32bit, you need to manually copy from FoxitPDFSDKPython2/x86 /_fsdk.so to FoxitPDFSDKPython2/. If you use python2.7 64bit, you need to manually copy from FoxitPDFSDKPython2/x64/_fsdk.so to FoxitPDFSDKPython2/. You can also run examples/rundemo_python.py for automatic copying.

How to run the examples

Use rundemo_python.py to run the examples on Python

This command will run all examples.

$ cd examples/simple_demo/

$ python rundemo_python.py

This command will run a single example annotation.

$ cd examples/simple_demo/

$ python rundemo_python.py annotation

Run the examples script directly with python.

For Python2.7, if _fsdk.so in the corresponding directory matches the current system python version, you can use python to run the examples directly. For the correspondence between _fsdk.so and python version, please see About package directory structure. For Python3, if you have installed FoxitPDFSDKPython3 module, you can use python to run the examples directly.

This command will run a single example annotation.

$ cd examples/simple_demo/annotation/

$ python -u annotation.py

Security, Signature and Paging_seal_signature demos

Before running security, signature and paging_seal_signature demos, please make sure that you have already installed cryptography and pyopenssl.

Note: Here we use cryptography 2.3 and pyopenssl 19.0.0,you can use the version higher than cryptography 2.3 and pyopenssl 19.0.0.

OCR demo

For how to run the ocr demo, please refer to section 3.34 “OCR”.

Compliance demo

For how to run the compliance demo, please refer to section 3.35 “Compliance”.

HTML to PDF demo

For how to run the html2pdf demo, please refer to section 3.37 “HTML to PDF Conversion”.

Output Preview demo

For how to run the output preview demo, please refer to section 3.39 “Output Preview”.

How to create a simple project

In this section, we will show you how to use Foxit PDF SDK for Linux Python to create a simple project that renders the first page of a PDF to a bitmap and saves it as a JPG image. Please follow the steps below:

Create a new project folder named “test_linux”.

Copy the ” SamplePDF.pdf” from the “foxitpdfsdk_9_0_linux_python/example/simple_demo/input_files” to the folder “test_linux”.

For Python2, copy the folder “FoxitPDFSDKPython2” from the “foxitpdfsdk_9_0_linux_python” to the folder “test_linux”. For Python3, run the command as “pip install FoxitPDFSDKPython3” to install the package from pypi.

Add the following Python script file “test_linux.py” to the folder “test_linux”.

Set the value of “sn” in test_linux.py with the string after “SN=” from “gsdk_sn.txt”.

Set the value of “key” in test_linux.py with the string after “Sign=” from “gsdk_key.txt”.

import sys

import site

import platform

from shutil import copyfile

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

# For Python2, copy the corresponding version of the dynamic library to the folder FoxitPDFSDKPython2.

if _PYTHON2_:

arch = platform.architecture()

if arch[0] == 32bit“:

src_lib_path = ./FoxitPDFSDKPython2/x86/_fsdk.so

elif arch[0] == 64bit“:

src_lib_path = ./FoxitPDFSDKPython2/x64/_fsdk.so

dest_lib_path = ./FoxitPDFSDKPython2/_fsdk.so

if src_lib_path is not None:

copyfile(src_lib_path, dest_lib_path)

if _PYTHON2_:

site.addsitedir(‘./‘)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Assuming PDFDoc doc has been loaded.

# The value of “sn” can be got from “gsdk_sn.txt” (the string after “SN=”).

# The value of “key” can be got from “gsdk_key.txt” (the string after “Sign=”).

sn =

key =

def main():

# Load a PDF document, and parse the first page of the document.

doc = PDFDoc(“SamplePDF.pdf“)

error_code = doc.Load(“”)

if error_code!= e_ErrSuccess:

return 0

page = doc.GetPage(0)

page.StartParse(PDFPage.e_ParsePageNormal, None, False)

width = int(page.GetWidth())

height = int(page.GetHeight())

matrix = page.GetDisplayMatrix(0, 0, width, height, page.GetRotation())

# Prepare a bitmap for rendering.

bitmap = Bitmap(width, height, Bitmap.e_DIBArgb)

bitmap.FillRect(0xFFFFFFFF, None)

# Render page.

render = Renderer(bitmap, False)

render.StartRender(page, matrix, None)

# Add the bitmap to image and save the image.

img = Image()

img.AddFrame(bitmap)

img.SaveAs(“testpage.jpg“)

return 0

if __name__ == __main__‘:

code = Library.Initialize(sn, key)

if code == e_ErrSuccess:

main()

Library.Release()

Run “test_linux.py” on the shell as “python test_linux.py”, and the “testpage.jpg” will be generated in current folder.

Mac

Mac for x64

In this guide, the highlighted rectangle in the figure is the version of the SDK. Here the SDK version is 9.0, so it shows 9_0.

What is in the package

Download the Foxit PDF SDK zip for Mac x64 Python package and extract it to a new directory “foxitpdfsdk_9_0_mac_python”. The structure of the release package is shown in Figure 2-3. This package contains the following folders:

doc: developer guide

examples: sample projects and demos

FoxitPDFSDKPython2: libraries and license files

res: the default icc profile files used for output preview demo

Figure 2-3

How to run a demo

Note: Starting from version 9.0, the version of clang used for building and compiling the Foxit PDF SDK for Mac (x64) has been upgraded from 9.1.0 to 11.0.3.

Requirement

Python 2.7 or 3.6-3.10 for x64, a single version of Python installed on the system is allowed.

Make sure that the default command is python and it is added in the system path environment variables.

Python 3.6-3.10 use pip to install FoxitPDFSDKPython3 module from pypi.

$ pip install FoxitPDFSDKPython3

Install third party modules using pip.

$ pip install cryptography==2.3

$ pip install pyopenssl==19.0.0

$ pip install uuid

How to run the examples

Use rundemo_python.py to run the examples on Python.

This command will run all examples.

$ cd examples/simple_demo/

$ python rundemo_python.py

This command will run a single example annotation.

$ cd examples/simple_demo/

$ python rundemo_python.py annotation

Run the examples script directly with python.

For Python2.7, you can use python to run the examples directly. For Python3, if you have installed FoxitPDFSDKPython3 module, you can use python to run the examples directly.

This command will run a single example annotation.

$ cd examples/simple_demo/annotation/

$ python -u annotation.py

Security, Signature and Paging_seal_signature demos

Before running security, signature and paging_seal_signature demos, please make sure that you have already installed cryptography and pyopenssl.

Note: Here we use cryptography 2.3 and pyopenssl 19.0.0,you can use the version higher than cryptography 2.3 and pyopenssl 19.0.0.

Compliance demo

For how to run the compliance demo, please refer to section 3.35 “Compliance”.

HTML to PDF demo

For how to run the html2pdf demo, please refer to section 3.37 “HTML to PDF Conversion”.

Output Preview demo

For how to run the output preview demo, please refer to section 3.39 “Output Preview”.

How to create a simple project

In this section, we will show you how to use Foxit PDF SDK for Mac Python to create a simple project that renders the first page of a PDF to a bitmap and saves it as a JPG image. Please follow the steps below:

Create a new project folder named “test_mac”.

Copy the ” SamplePDF.pdf” from the “foxitpdfsdk_9_0_mac_python/example/simple_demo/input_files” to the folder “test_mac”.

For Python2, copy the folder “FoxitPDFSDKPython2” from the “foxitpdfsdk_9_0_mac_python” to the folder “test_mac “. For Python3, run the command as “pip install FoxitPDFSDKPython3” to install the package from pypi.

Add the following Python script file “test_mac.py” to the folder “test_mac “.

Set the value of “sn” in test_mac.py with the string after “SN=” from “gsdk_sn.txt”.

Set the value of “key” in test_mac.py with the string after “Sign=” from “gsdk_key.txt”.

import sys

import site

import platform

from shutil import copyfile

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

site.addsitedir(‘./‘)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Assuming PDFDoc doc has been loaded.

# The value of “sn” can be got from “gsdk_sn.txt” (the string after “SN=”).

# The value of “key” can be got from “gsdk_key.txt” (the string after “Sign=”).

sn =

key =

def main():

# Load a PDF document, and parse the first page of the document.

doc = PDFDoc(“SamplePDF.pdf“)

error_code = doc.Load(“”)

if error_code!= e_ErrSuccess:

return 0

page = doc.GetPage(0)

page.StartParse(PDFPage.e_ParsePageNormal, None, False)

width = int(page.GetWidth())

height = int(page.GetHeight())

matrix = page.GetDisplayMatrix(0, 0, width, height, page.GetRotation())

# Prepare a bitmap for rendering.

bitmap = Bitmap(width, height, Bitmap.e_DIBArgb)

bitmap.FillRect(0xFFFFFFFF, None)

# Render page.

render = Renderer(bitmap, False)

render.StartRender(page, matrix, None)

# Add the bitmap to image and save the image.

img = Image()

img.AddFrame(bitmap)

img.SaveAs(“testpage.jpg“)

return 0

if __name__ == __main__‘:

code = Library.Initialize(sn, key)

if code == e_ErrSuccess:

main()

Library.Release()

Run “test_mac.py” on the shell as “python test_mac.py”, and the “testpage.jpg” will be generated in current folder.

Mac for arm64

From version 9.0, Foixt PDF SDK for Python API provides arm64 python libraries for MacOS with ARM64 framework.

In this guide, the highlighted rectangle in the figure is the version of the SDK. Here the SDK version is 9.0, so it shows 9.0

What is in the package

Download the Foxit PDF SDK zip for Mac arm64 Python package and extract it to a new directory “foxitpdfsdk_9_0_mac_arm64_python”. The structure of the release package is shown in Figure 2-4. This package contains the following folders:

doc: developer guide

examples: sample projects and demos

FoxitPDFSDKPython2: libraries and license files

Figure 2-4

How to run a demo

Requirement

Python 2.7 or 3.8-3.10 for arm64, a single version of Python installed on the system is allowed.

Make sure that the default command is python and it is added in the system path environment variables.

Python 3.8-3.10 use pip to install FoxitPDFSDKPython3 module from pypi.

$ pip install FoxitPDFSDKPython3

Install third party modules using pip.

$ pip install cryptography==2.3

$ pip install pyopenssl==19.0.0

$ pip install uuid

How to run the examples

Use rundemo_python.py to run the examples on Python.

This command will run all examples.

$ cd examples/simple_demo/

$ python rundemo_python.py

This command will run a single example annotation.

$ cd examples/simple_demo/

$ python rundemo_python.py annotation

Run the examples script directly with python.

For Python2.7, you can use python to run the examples directly. For Python3, if you have installed FoxitPDFSDKPython3 module, you can use python to run the examples directly.

This command will run a single example annotation.

$ cd examples/simple_demo/annotation/

$ python -u annotation.py

Security, Signature and Paging_seal_signature demos

Before running security, signature and paging_seal_signature demos, please make sure that you have already installed cryptography and pyopenssl.

Note: Here we use cryptography 2.3 and pyopenssl 19.0.0,you can use the version higher than cryptography 2.3 and pyopenssl 19.0.0.

Compliance demo

For how to run the compliance demo, please refer to section 3.35 “Compliance”.

HTML to PDF demo

For how to run the html2pdf demo, please refer to section 3.37 “HTML to PDF Conversion”.

How to create a simple project

In this section, we will show you how to use Foxit PDF SDK for Mac arm64 Python to create a simple project that renders the first page of a PDF to a bitmap and saves it as a JPG image. Please follow the steps below:

Create a new project folder named “test_mac”.

Copy the ” SamplePDF.pdf” from the “foxitpdfsdk_9_0_mac_arm64_python/example/simple_demo/input_files” to the folder “test_mac”.

For Python2, copy the folder “FoxitPDFSDKPython2” from the “foxitpdfsdk_9_0_mac_arm64_python” to the folder “test_mac “. For Python3, run the command as “pip install FoxitPDFSDKPython3” to install the package from pypi.

Add the following Python script file “test_mac.py” to the folder “test_mac “.

Set the value of “sn” in test_mac.py with the string after “SN=” from “gsdk_sn.txt”.

Set the value of “key” in test_mac.py with the string after “Sign=” from “gsdk_key.txt”.

import sys

import site

import platform

from shutil import copyfile

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

site.addsitedir(‘./‘)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Assuming PDFDoc doc has been loaded.

# The value of “sn” can be got from “gsdk_sn.txt” (the string after “SN=”).

# The value of “key” can be got from “gsdk_key.txt” (the string after “Sign=”).

sn =

key =

def main():

# Load a PDF document, and parse the first page of the document.

doc = PDFDoc(“SamplePDF.pdf“)

error_code = doc.Load(“”)

if error_code!= e_ErrSuccess:

return 0

page = doc.GetPage(0)

page.StartParse(PDFPage.e_ParsePageNormal, None, False)

width = int(page.GetWidth())

height = int(page.GetHeight())

matrix = page.GetDisplayMatrix(0, 0, width, height, page.GetRotation())

# Prepare a bitmap for rendering.

bitmap = Bitmap(width, height, Bitmap.e_DIBArgb)

bitmap.FillRect(0xFFFFFFFF, None)

# Render page.

render = Renderer(bitmap, False)

render.StartRender(page, matrix, None)

# Add the bitmap to image and save the image.

img = Image()

img.AddFrame(bitmap)

img.SaveAs(“testpage.jpg“)

return 0

if __name__ == __main__‘:

code = Library.Initialize(sn, key)

if code == e_ErrSuccess:

main()

Library.Release()

Run “test_mac.py” on the shell as “python test_mac.py”, and the “testpage.jpg” will be generated in current folder.


WORKING WITH SDK API

In this section, we will introduce a set of major features and list some examples for each feature to show you how to integrate powerful PDF capabilities with your applications using Foxit PDF SDK Python API.

Initialize Library

It is necessary for applications to initialize Foxit PDF SDK before calling any APIs. The function Library.Initialize is provided to initialize Foxit PDF SDK. A license should be purchased for the application and pass unlock key and code to get proper supports. When there is no need to use Foxit PDF SDK any more, please call function Library.Release to release it.

Note The parameter “sn” can be found in the “gsdk_sn.txt” (the string after “SN=”) and the “key” can be found in the “gsdk_key.txt” (the string after “Sign=”).

Example:

How to initialize Foxit PDF SDK

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

#replace with the python2 lib path

site.addsitedir(‘../../../’)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

sn =

key =

code = Library.Initialize(sn, key)

if code != e_ErrSuccess:

return False

Document

A PDF document object can be constructed with an existing PDF file from file path, memory buffer, a custom implemented ReaderCallback object and an input file stream. Then call function PDFDoc.Load or PDFDoc.StartLoad to load document content. A PDF document object is used for document level operation, such as opening and closing files, getting page, metadata and etc.

Example:

How to create a PDF document from scratch

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

# replace with the python2 lib path

site.addsitedir(‘../../../’)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

doc = PDFDoc()

Note: It creates a new PDF document without any pages.

How to load an existing PDF document from file path

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

# replace with the python2 lib path

site.addsitedir(‘../../../’)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

doc = PDFDoc(“Sample.pdf“)

error_code = doc.Load(“”)

if error_code!= e_ErrSuccess:

return 0

How to load an existing PDF document from a memory buffer

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

# replace with the python2 lib path

site.addsitedir(‘../../../’)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

file = open(“blank.pdf“, rb“)

if file == None:

return 0

file.seek(0, os.SEEK_END)

file_size = file.tell()

buffer = file.read(file_size)

file.close()

doc = PDFDoc(buffer, file_size)

error_code = doc.Load()

if error_code!= e_ErrSuccess:

return 0

How to load an existing PDF document from a file read callback object

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

# replace with the python2 lib path

site.addsitedir(‘../../../’)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

class CFSFile_Read(FileReaderCallback):

def __init__(self, *args):

if _PYTHON2_:

super(CFSFile_Read, self).__init__()

else:

super().__init__()

self.file_ = None

self.offset_ = args[0]

def __del__(self):

self.__disown__()

def Release(self, *args):

self.file_.close()

def LoadFile(self, *args):

self.file_ = open(args[0], rb“)

if self.file_ is not None:

return True

else:

return False

def GetSize(self, *args):

return self.offset_

def ReadBlock(self, *args):

if self.file_ is None:

return False, None

size = 0

if len(args) == 2:

self.file_.seek(args[0], 0)

size = args[1]

elif len(args) == 1:

size = args[0]

else:

return False, None

buffer = self.file_.read(size)

return True, buffer

input_pdf_path = Sample.pdf

file_read = CFSFile_Read()

if not file_read.LoadFile(input_pdf_path):

return

doc = PDFDoc(file_read)

error_code = doc.Load()

if error_code!= e_ErrSuccess:

return 0

How to load PDF document and get the first page of the PDF document

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

# replace with the python2 lib path

site.addsitedir(‘../../../’)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

doc =PDFDoc(“Sample.pdf“)

error_code = doc.Load(“”)

if error_code!= e_ErrSuccess:

return 0

page = doc.GetPage(0)

page.StartParse(PDFPage.e_ParsePageNormal, None, False)

How to save a PDF to a file

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

# replace with the python2 lib path

site.addsitedir(‘../../../‘)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

doc = PDFDoc(“Sample.pdf“)

error_code = doc.Load(“”)

if error_code!= e_ErrSuccess:

return 0

doc.SaveAs(“new_Sample.pdf“, PDFDoc.e_SaveFlagNoOriginal)

How to save a document into memory buffer by WriterCallback

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

# replace with the python2 lib path

site.addsitedir(‘../../../’)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

class FileWriter(FileWriterCallback):

def __init__(self, *args):

if _PYTHON2_:

super(FileWriter, self).__init__()

else:

super().__init__()

self.binary_buffer_ = bytearray(b”)

def __del__(self):

self.__disown__()

def Release(self, *args):

pass

def GetSize(self, *args):

file_size = len(self.binary_buffer_)

return file_size

def ReadBlock(self, *args):

size = 0

if len(args) == 2:

offset = args[0]

size = args[1]

buffer = bytes(self.binary_buffer_[offset:offset+size])

return True, buffer

else:

return False, None

def Flush(self, *args):

return True

def WriteBlock(self, *args):

self.binary_buffer_[args[0][1]:0] = args[0][0]

return True

file_writer = FileWriter()

# Assuming PDFDoc doc has been loaded.

doc.StartSaveAs(file_writer, PDFDoc.e_SaveFlagNoOriginal)

Page

PDF Page is the basic and important component of PDF Document. A PDFPage object is retrieved from a PDF document by function PDFDoc.GetPage. Page level APIs provide functions to parse, render, edit (includes creating, deleting, flattening and etc.) a page, retrieve PDF annotations, read and set the properties of a page, and etc. For most cases, A PDF page needs to be parsed before it is rendered or processed.

Example:

How to get page size

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

#replace with the python2 lib path

site.addsitedir(‘../../../’)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Assuming PDFPage page has been loaded and parsed.

width = int(page.GetWidth())

height = int(page.GetHeight())

How to calculate bounding box of page contents

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

#replace with python2 lib path

site.addsitedir(‘../../../‘)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Assuming PDFDoc doc has been loaded.

# Assuming PDFPage page has been loaded and parsed.

ret = page.CalcContentBBox(PDFPage.e_CalcContentsBox)

How to create a PDF page and set the size

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

# replace with the python2 lib path

site.addsitedir(‘../../../’)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Assuming PDFDoc doc has been loaded.

page = doc.InsertPage(index, PageWidth, PageHeight)

How to delete a PDF page

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

#replace with the python2 lib path

site.addsitedir(‘../../../’)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Assuming PDFDoc doc has been loaded.

# Remove a PDF page by page index.

doc.RemovePage(index)

# Remove a specified PDF page.

doc.RemovePage(page)

How to flatten a PDF page

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

# replace with python2 lib path

site.addsitedir(‘../../../‘)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

page = PDFPage()

# Assuming PDFPage page has been loaded and parsed.

# Flatten all contents of a PDF page.

page.Flatten(True, PDFPage.e_FlattenAll)

# Flatten a PDF page without annotations.

page.Flatten(True, PDFPage.e_FlattenNoAnnot)

# Flatten a PDF page without form controls.

page.Flatten(True, PDFPage.e_FlattenNoFormControl)

# Flatten a PDF page without annotations and form controls (Equals to nothing to be flattened).

page.Flatten(True, PDFPage.e_FlattenNoAnnot | PDFPage.e_FlattenNoFormControl)

How to get and set page thumbnails in a PDF document

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

# replace with the python2 lib path

site.addsitedir(‘../../../’)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Assuming PDFPage page has been loaded and parsed.

bmp = Bitmap()

# Write bitmap data to the bmp object.

# Set thumbnails to the page.

page.SetThumbnail(bmp)

# Load thumbnails in the page.

bitmap = page.LoadThumbnail()

Render

PDF rendering is realized through the Foxit renderer, a graphic engine that is used to render page to a bitmap or platform graphics device. Foxit PDF SDK provides APIs to set rendering options/flags, for example set flag to decide whether to render form fields and signature, whether to draw image anti-aliasing and path anti-aliasing. To do rendering, you can use the following APIs:

To render page and annotations, first use function Renderer.SetRenderContentFlags to decide whether to render page and annotation both or not, and then use function Renderer.StartRender to do the rendering. Function Renderer.StartQuickRender can also be used to render page but only for thumbnail purpose.

To render a single annotation, use function Renderer.RenderAnnot.

To render on a bitmap, use function Renderer.StartRenderBitmap.

To render a reflowed page, use function Renderer.StartRenderReflowPage.

Widget annotation is always associated with form field and form control in Foxit PDF SDK. For how to render widget annotations, here is a recommended flow:

After loading a PDF page, first render the page and all annotations in this page (including widget annotations).

Then, if use Filler object to fill the form, the function Filler.Render should be used to render the focused form control instead of the function Renderer.RenderAnnot.

Example:

How to render a page to a bitmap

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

# replace with the python2 lib path

site.addsitedir(‘../../../’)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Assuming PDFPage page has been loaded and parsed.

width = int(page.GetWidth())

height = int(page.GetHeight())

matrix = page.GetDisplayMatrix(0, 0, width, height, page.GetRotation())

# Prepare a bitmap for rendering.

bitmap = Bitmap(width, height, Bitmap.e_DIBArgb)

bitmap.FillRect(0xFFFFFFFF, None)

# Render page.

render = Renderer(bitmap, False)

render.StartRender(page, matrix, None)

How to render page and annotation

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

# replace with the python2 lib path

site.addsitedir(‘../../../’)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Assuming PDFPage page has been loaded and parsed.

width = int(page.GetWidth())

height = int(page.GetHeight())

matrix = page.GetDisplayMatrix(0, 0, width, height, page.GetRotation())

# Prepare a bitmap for rendering.

bitmap = Bitmap(width, height, Bitmap.e_DIBArgb)

bitmap.FillRect(0xFFFFFFFF, None)

render = Renderer(bitmap, False)

dwRenderFlag = Renderer.e_RenderAnnot | Renderer.e_RenderPage

render.SetRenderContentFlags(dwRenderFlag)

render.StartRender(page, matrix, None)

Attachment

In Foxit PDF SDK, attachments are only referred to attachments of documents rather than file attachment annotation, which allow whole files to be encapsulated in a document, much like email attachments. PDF SDK provides applications APIs to access attachments such as loading attachments, getting attachments, inserting/removing attachments, and accessing properties of attachments.

Example:

How to export the embedded attachment file from a PDF and save it as a single file

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

#replace with the python2 lib path

site.addsitedir(‘../../../‘)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Assuming PDFDoc doc has been loaded.

# Get information of attachments.

attachments = Attachments(doc)

count = attachments.GetCount()

for i in range(0, count):

key = attachments.GetKey(i)

file_spec = attachments.GetEmbeddedFile(key)

if not file_spec.IsEmpty():

name = file_spec.GetFileName()

if file_spec.IsEmbedded():

exFilePath = output_directory

file_spec.ExportToFile(exFilePath)

How to remove all the attachments of a PDF

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

#replace with the python2 lib path

site.addsitedir(‘../../../’)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Assuming PDFDoc doc has been loaded.

# Get information of attachments.

attachments = Attachments(doc)

count = attachments.GetCount()

for i in range(0, count):

key = attachments.GetKey(i)

attachments.RemoveEmbeddedFile(key)

Text Page

Foxit PDF SDK provides APIs to extract, select, search and retrieve text in PDF documents. PDF text contents are stored in TextPage objects which are related to a specific page. TextPage class can be used to retrieve information about text in a PDF page, such as single character, single word, text content within specified character range or rectangle and so on. It also can be used to construct objects of other text related classes to do more operations for text contents or access specified information from text contents:

To search text in text contents of a PDF page, construct a TextSearch object with TextPage object.

To access text such like hypertext link, construct a PageTextLinks object with TextPage object.

Example:

How to extract text from a PDF page

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

# replace with the python2 lib path

site.addsitedir(‘../../../’)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Assuming PDFPage page has been loaded and parsed.

# Get the text page object.

text_page = TextPage(page)

count = text_page.GetCharCount()

if count > 0:

text = text_page.GetChars()

if _PYTHON2_:

file.write(text)

else:

file.write(bytes(text, encoding=”utf-8“))

How to get the text within a rectangle area in a PDF

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

# replace with the python2 lib path

site.addsitedir(‘../../../’)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

rect = RectF()

rect.left = 90

rect.right = 450

rect.top = 595

rect.bottom = 580

textPage = TextPage(page, TextPage.e_ParseTextNormal)

textPage.GetTextInRect(rect)

Text Search

Foxit PDF SDK provides APIs to search text in a PDF document, a XFA document, a text page or in a PDF annotation’s appearance. It offers functions to do a text search and get the searching result:

To specify the searching pattern and options, use functions TextSearch.SetPattern, TextSearch.SetStartPage (only useful for a text search in PDF document), TextSearch.SetEndPage (only useful for a text search in PDF document) and TextSearch.SetSearchFlags.

To do the searching, use function TextSearch.FindNext or TextSearch.FindPrev.

To get the searching result, use function TextSearch.GetMatchXXX().

Example:

How to search a text pattern in a PDF

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

site.addsitedir(‘../../../’)

#replace with python2 lib path

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Assuming PDFDoc doc has been loaded.

# Search for all pages of doc.

search = TextSearch(doc, None)

start_index = 0

end_index = doc.GetPageCount() 1

search.SetStartPage(start_index)

search.SetEndPage(end_index)

pattern = Foxit

search.SetPattern(pattern)

flags = TextSearch.e_SearchNormal

search.SetSearchFlags(flags)

match_count = 0

while search.FindNext():

rect_array = search.GetMatchRects()

match_count = match_count + 1

Text Link

In a PDF page, some text contents that represent a hypertext link to a website or a resource on the intent, or an email address are the same with common texts. Prior to text link processing, user should first call PageTextLinks.GetTextLink to get a textlink object.

Example:

How to retrieve hyperlinks in a PDF page

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

# replace with python2 lib path

site.addsitedir(‘../../../‘)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Assuming PDFPage page has been loaded and parsed.

# Get the text page object.

text_page = TextPage(page)

pageTextLink = PageTextLinks(text_page)

textLink = pageTextLink.GetTextLink(index)

strURL = textLink.GetURI()

Bookmark

Foxit PDF SDK provides navigational tools called Bookmarks to allow users to quickly locate and link their point of interest within a PDF document. PDF bookmark is also called outline, and each bookmark contains a destination or actions to describe where it links to. It is a tree-structured hierarchy, so function PDFDoc.GetRootBookmark must be called first to get the root of the whole bookmark tree before accessing to the bookmark tree. Here, “root bookmark” is an abstract object which can only have some child bookmarks without next sibling bookmarks and any data (includes bookmark data, destination data and action data). It cannot be shown on the application UI since it has no data. Therefore, a root bookmark can only call function Bookmark.GetFirstChild.

After the root bookmark is retrieved, following functions can be called to access other bookmarks:

To access the parent bookmark, use function Bookmark.GetParent.

To access the first child bookmark, use function Bookmark.GetFirstChild.

To access the next sibling bookmark, use function Bookmark.GetNextSibling.

To insert a new bookmark, use function Bookmark.Insert.

To move a bookmark, use function Bookmark.MoveTo.

Example:

How to find and list all bookmarks of a PDF

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

#replace with the python2 lib path

site.addsitedir(‘../../../‘)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Assuming PDFDoc doc has been loaded.

root = doc.GetRootBookmark()

first_bookmark = root.GetFirstChild()

def TraverseBookmark(root, iLevel):

if root is not None:

child = root.GetFirstChild()

while child is not None:

TraverseBookmark(child, iLevel + 1)

child = child.GetNextSibling()

if first_bookmark is not None:

TraverseBookmark(first_bookmark, 0)

How to insert a new bookmark

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

#replace with the python2 lib path

site.addsitedir(‘../../../‘)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Assuming PDFDoc doc has been loaded.

root = doc.GetRootBookmark()

if root.IsEmpty():

root = doc.CreateRootBookmark()

dest = Destination.CreateFitPage(doc, 0)

ws_title = str.format(“A bookmark to a page (index: {})“, 0)

child = root.Insert(ws_title, Bookmark.e_PosLastChild)

child.SetDestination(dest)

child.SetColor(0xF68C21)

How to create a table of contents based on bookmark information in PDFs

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

#replace with the python2 lib path

site.addsitedir(‘../../../‘)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

def AddTOCToPDF(doc):

# Set the table of contents configuration.

intarray = Int32Array()

depth = doc.GetBookmarkLevelDepth()

if depth > 0:

for i in range(1, depth):

intarray.Add(i)

title = “”

toc_config = TableOfContentsConfig(title, intarray, True, False)

#Add the table of contents

doc.AddTableOfContents(toc_config)


Form (AcroForm)

PDF currently supports two different forms for gathering information interactively from the user – AcroForms and XFA forms. Acroforms are the original PDF-based fillable forms, based on the PDF architecture. Foxit PDF SDK provides APIs to view and edit form field programmatically. Form fields are commonly used in PDF documents to gather data. The Form class offers functions to retrieve form fields or form controls, import/export form data and other features, for example:

To retrieve form fields, please use functions Form.GetFieldCount and Form.GetField.

To retrieve form controls from a PDF page, please use functions Form.GetControlCount and Form.GetControl.

To import form data from an XML file, please use function Form.ImportFromXML; to export form data to an XML file, please use function Form.ExportToXML.

To retrieve form filler object, please use function Form.GetFormFiller.

To import form data from a FDF/XFDF file or export such data to a FDF/XFDF file, please refer to functions PDFDoc.ImportFromFDF and PDFDoc.ExportToFDF.

Example:

How to load the forms in a PDF

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

#replace with the python2 lib path

site.addsitedir(‘../../../‘)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Assuming PDFDoc doc has been loaded.

hasForm = doc.HasForm()

if hasForm:

form = Form(doc)

How to count form fields and get/set the properties

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

#replace with the python2 lib path

site.addsitedir(‘../../../‘)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Assuming PDFDoc doc has been loaded.

form = Form(doc)

countFields = form.GetFieldCount(“”)

for i in range(0, countFields):

field = form.GetField(i, filter)

type = field.GetType()

org_alternateName = field.GetAlternateName()

field.SetAlternateName(“signature“)

How to export the form data in a PDF to a XML file

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

#replace with the python2 lib path

site.addsitedir(‘../../../‘)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Assuming PDFDoc doc has been loaded.

form = Form(doc)

form.ExportToXML(XMLFilePath)

How to import form data from a XML file

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

#replace with the python2 lib path

site.addsitedir(‘../../../‘)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Assuming PDFDoc doc has been loaded.

form = Form(doc)

form.ImportFromXML(XMLFilePath)

How to get coordinates of a form field

Load PDF file by PDFDoc.

Traverse the form fields of the PDFDoc to get the field object of form.

Traverse the form controls of the field object to get the form control object.

Get the related widget annotation object by form control.

Call the GetRect of the widget annotation object to get the coordinate of the form.

import os

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

site.addsitedir(‘../../../‘)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Load a document

doc = PDFDoc(input_file)

error_code = doc.Load(“”)

if error_code != e_ErrSuccess:

print(“The PDFDoc {} Error: {}.format(input_file, error_code))

return 1

if not doc.HasForm(): return 1

form = Form(doc);

for i in range(0, form.GetFieldCount(“”)):

field = form.GetField(i, “”)

if field.IsEmpty(): continue

for j in range(0, field.GetControlCount()):

control = field.GetControl(j)

widget = control.GetWidget()

# Get rectangle of the annot widget.

rect = widget.GetRect()

XFA Form

XFA (XML Forms Architecture) forms are XML-based forms, wrapped inside a PDF. The XML Forms Architecture provides a template-based grammar and a set of processing rules that allow uses to build interactive forms. At its simplest, a template-based grammar defines fields in which a user provides data.

Foxit PDF SDK provides APIs to render the XFA form, fill the form, export or import form’s data.

Note:

Foxit PDF SDK provides two callback classes AppProviderCallback and DocProviderCallback to represent the callback objects as an XFA document provider and an XFA application provider respectively. All the functions in those classes are used as callback functions. Pure virtual functions should be implemented by users.

To use the XFA form feature, please make sure the license key has the permission of the ‘XFA’ module.

Example:

How to load XFADoc and represent an Interactive XFA form

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

#replace with the python2 lib path

site.addsitedir(‘../../../‘)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

pXFAAppHandler = nCFS_XFAAppHandler()

# implement from AppProviderCallback

Library.RegisterXFAAppProviderCallback(pXFAAppHandler)

input_file = input_path + xfa_dynamic.pdf

doc = PDFDoc(input_file)

error_code = doc.Load(“”)

if error_code != e_ErrSuccess:

return 1

pXFADocHandler = CFS_XFADocHandler();

# implement from DocProviderCallback

xfa_doc = XFADoc(doc, pXFADocHandler)

xfa_doc.StartLoad(“”)

How to export and import XFA form data

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

#replace with the python2 lib path

site.addsitedir(‘../../../‘)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Assuming FSXFADoc xfa_doc has been loaded.

xfa_doc.ExportData(“xfa_form.xml“, XFADoc.e_ExportDataTypeXML)

xfa_doc.ResetForm()

doc.SaveAs(“xfa_dynamic_resetform.pdf“)

xfa_doc.ImportData(“xfa_form.xml“)

doc.SaveAs(“xfa_dynamic_importdata.pdf“)

Form Filler

Form filler is the most commonly used feature for users. Form filler allows applications to fill forms dynamically. The key point for applications to fill forms is to construct some callback functions for PDF SDK to call. To fill the form, please construct a Filler object by current Form object or retrieve the Filler object by function Form.GetFormFiller if such object has been constructed. (There should be only one form filler object for an interactive form).

Form Design

Fillable PDF forms (AcroForm) are especially convenient for preparation of various applications, such as taxes and other government forms. Form design provides APIs to add or remove form fields (Acroform) to or from a PDF file. Designing a form from scratch allows developers to create the exact content and layout of the form they want.

Example:

How to add a text form field to a PDF

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

#replace with the python2 lib path

site.addsitedir(‘../../../‘)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Assuming PDFDoc doc has been loaded.

# Assuming PDFPage page has been loaded and parsed.

# Add text field

control = form.AddControl(page, Text Field0“, Field.e_TypeTextField, RectF(50, 600, 90, 640))

control.GetField().SetValue(“3“)

# Update text field’s appearance.

control.GetWidget().ResetAppearanceStream()

control1 = form.AddControl(page, “Text Field1”, Field.e_TypeTextField, RectF(100, 600, 140, 640))

control1.GetField().SetValue(“123”)

# Update text fields appearance.

control1.GetWidget().ResetAppearanceStream()

How to remove a text form field from a PDF

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

#replace with the python2 lib path

site.addsitedir(‘../../../‘)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Assuming PDFDoc doc has been loaded.

form = Form(doc)

filter = text1

countFields = form.GetFieldCount(“”)

for i in range(0, countFields):

field = form.GetField(i, filter)

if field.GetType() == Field.e_TypeTextField:

form.RemoveField(field)

Annotations

General

An annotation associates an object such as note, line, and highlight with a location on a page of a PDF document. It provides a way to interact with users by means of the mouse and keyboard. PDF includes a wide variety of standard annotation types as listed in Table 3. Among these annotation types, many of them are defined as markup annotations for they are used primarily to mark up PDF documents. These annotations have text that appears as part of the annotation and may be displayed in other ways by a conforming reader, such as in a Comments pane. The ‘Markup’ column in Table 3 shows whether an annotation is a markup annotation.

Foxit PDF SDK supports most annotation types defined in PDF reference [1]. PDF SDK provides APIs of annotation creation, properties access and modification, appearance setting and drawing.

Table 31

Annotation type Description Markup Supported by SDK
Text(Note) Text annotation Yes Yes
Link Link Annotation No Yes
FreeText (TypeWritter/TextBox/Callout) Free text annotation Yes Yes
Line Line annotation Yes Yes
Square Square annotation Yes Yes
Circle Circle annotation Yes Yes
Polygon Polygon annotation Yes Yes
PolyLine PolyLine annotation Yes Yes
Highlight Highlight annotation Yes Yes
Underline Underline annotation Yes Yes
Squiggly Squiggly annotation Yes Yes
StrikeOut StrikeOut annotation Yes Yes
Stamp Stamp annotation Yes Yes
Caret Caret annotation Yes Yes
Ink(pencil) Ink annotation Yes Yes
Popup Popup annotation No Yes
File Attachment FileAttachment annotation Yes Yes
Sound Sound annotation Yes No
Movie Movie annotation No No
Widget* Widget annotation No Yes
Screen Screen annotation No Yes
PrinterMark PrinterMark annotation No No
TrapNet Trap network annotation No No
Watermark* Watermark annotation No Yes
3D 3D annotation No No
Redact Redact annotation Yes Yes

Note:

The annotation types of widget and watermark are special. They aren’t supported in the module of ‘Annotation’. The type of widget is only used in the module of ‘form filler’ and the type of watermark only in the module of ‘watermark’.

Foxit SDK supports a customized annotation type called PSI (pressure sensitive ink) annotation that is not described in PDF reference [1]. Usually, PSI is for handwriting features and Foxit SDK treats it as PSI annotation so that it can be handled by other PDF products.

Example:

How to add a link annotation to a PDF page

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

#replace with the python2 lib path

site.addsitedir(‘../../../‘)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Assuming PDFPage page has been loaded and parsed.

# Assuming the annnots in the page have been loaded.

# Add link annotation.

link = Link(page.AddAnnot(Annot.e_Link, RectF(350,350,380,400)))

link.SetHighlightingMode(Annot.e_HighlightingToggle)

How to add a highlight annotation to a page and set the related annotation properties

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

#replace with the python2 lib path

site.addsitedir(‘../../../‘)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Assuming PDFPage page has been loaded and parsed.

# Assuming the annnots in the page have been loaded.

# Add highlight annotation.

highlight = Highlight(page.AddAnnot(Annot.e_Highlight,RectF(10,450,100,550)))

highlight.SetContent(“Highlight“)

quad_points = QuadPoints()

quad_points.first = PointF(10, 500)

quad_points.second = PointF(90, 500)

quad_points.third = PointF(10, 480)

quad_points.fourth = PointF(90, 480)

quad_points_array = QuadPointsArray()

quad_points_array.Add(quad_points)

highlight.SetQuadPoints(quad_points_array)

highlight.SetSubject(“Highlight“)

highlight.SetTitle(“Foxit SDK“)

highlight.SetCreationDateTime(GetLocalDateTime())

highlight.SetModifiedDateTime(GetLocalDateTime())

highlight.SetUniqueID(RandomUID())

# Appearance should be reset.

highlight.ResetAppearanceStream()

How to set the popup information when creating markup annotations

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

#replace with the python2 lib path

site.addsitedir(‘../../../‘)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Assuming PDFPage page has been loaded and parsed.

# Assuming the annnots in the page have been loaded.

# Create a new note annot and set the properties for it.

note = Note(page.AddAnnot(Annot.e_Note, RectF(10,350,50,400)))

note.SetIconName(“Comment“)

note.SetSubject(“Note“)

note.SetTitle(“Foxit SDK“)

note.SetContent(“Note annotation.“)

note.SetCreationDateTime(GetLocalDateTime())

note.SetModifiedDateTime(GetLocalDateTime())

note.SetUniqueID(RandomUID())

# Create a new popup annot and set it to the new note annot.

popup = Popup(page.AddAnnot(Annot.e_Popup, RectF(300,450,500,550)))

popup.SetBorderColor(0x00FF00)

popup.SetOpenStatus(False)

popup.SetModifiedDateTime(GetLocalDateTime())

note.SetPopup(popup)

How to get a specific annotation in a PDF using device coordinates

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

#replace with the python2 lib path

site.addsitedir(‘../../../‘)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Assuming PDFDoc doc has been loaded.

# Assuming PDFPage page has been loaded and parsed.

width = int(page.GetWidth())

height = int(page.GetHeight())

# Get page transformation matrix.

displayMatrix= page.GetDisplayMatrix(0, 0, width, height, page.GetRotation())

iAnnotCount = page.GetAnnotCount()

for i in range(0, iAnnotCount):

pAnnot = page.GetAnnot(i)

if Annot.e_Popup == pAnnot.GetType(): continue

annotRect = pAnnot.GetDeviceRect(False, displayMatrix)

pt = PointF()

float tolerance = 1.0

# Get the same annot (pAnnot) using annotRect.

pt.x = annotRect.left + tolerance

pt.y = (annotRect.top annotRect.bottom)/2 + annotRect.bottom

gAnnot = page.GetAnnotAtDevicePoint(pt, tolerance, displayMatrix)

How to extract the texts under text markup annotations

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

#replace with the python2 lib path

site.addsitedir(‘../../../‘)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Assuming PDFDoc doc has been loaded.

page = doc.GetPage(0)

# Parse the first page.

page.StartParse(PDFPage.e_ParsePageNormal, None, False)

annot_count = page.GetAnnotCount()

text_page = TextPage(page)

for i in range(0, annot_count):

annot = page.GetAnnot(i)

text_markup = TextMarkup(annot)

if not text_markup.IsEmpty():

# Get the texts which intersect with a text markup annotation.

text = text_page.GetTextUnderAnnot(text_markup)

How to add richtext for freetext annotation

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

#replace with the python2 lib path

site.addsitedir(‘../../../‘)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Make sure that SDK has already been initialized successfully.

# Load a PDF document, get a PDF page and parse it.

# Add a new freetext annotation, as text box.

freetext = FreeText(pdf_page.AddAnnot(Annot.e_FreeText, RectF(50, 50, 150, 100)))

# Set annotation’s properties.

# Add/insert richtext string with style.

richtext_style = RichTextStyle()

richtext_style.font = Font(“Times New Roman“, 0, Font.e_CharsetANSI, 0)

richtext_style.text_color = 0xFF0000

richtext_style.text_size = 10

freetext.AddRichText(“Textbox annotation “, richtext_style)

richtext_style.text_color = 0x00FF00

richtext_style.is_underline = True

freetext.AddRichText(“1-underline “, richtext_style)

richtext_style.font = Font(“Calibri“, 0, Font.e_CharsetANSI, 0)

richtext_style.text_color = 0x0000FF

richtext_style.is_underline = False

richtext_style.is_strikethrough = True

richtext_count = freetext.GetRichTextCount()

freetext.InsertRichText(richtext_count – 1, “2_strikethrough “, richtext_style)

# Appearance should be reset.

freetext.ResetAppearanceStream()

Import annotations from or export annotations to a FDF file

In Foxit PDF SDK, annotations can be created with data not only from applications but also from FDF files. At the same time, PDF SDK supports to export annotations to FDF files.

Example:

How to load annotations from a FDF file and add them into the first page of a given PDF

fdf_doc = FDFDoc(buffer, file_size)

pdf_doc.ImportFromFDF(fdf_doc, PDFDoc.e_Annots)

Image Conversion

Foxit PDF SDK provides APIs for conversion between PDF files and images. Applications could easily fulfill functionalities like image creation and image conversion which supports the following image formats: BMP, TIFF, PNG, JPX, JPEG, and GIF. Foxit PDF SDK can make the conversion between PDF files and the supported image formats except for GIF. It only supports converting GIF images to PDF files.

Example:

How to convert PDF pages to bitmap files

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

#replace with the python2 lib path

site.addsitedir(‘../../../‘)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Assuming PDFDoc doc has been loaded.

# Get page count

nPageCount = doc.GetPageCount()

for i in range(0, nPageCount):

page = doc.GetPage(i)

# Parse page.

page.StartParse(PDFPage.e_ParsePageNormal, None, False)

width = int(page.GetWidth())

height = int(page.GetHeight())

matrix = page.GetDisplayMatrix(0, 0, width, height, page.GetRotation())

# Prepare a bitmap for rendering.

bitmap = Bitmap(width, height, Bitmap.e_DIBArgb)

bitmap.FillRect(0xFFFFFFFF, None)

# Render page.

render = Renderer(bitmap, False)

render.StartRender(page, matrix, None)

image.AddFrame(bitmap)

Note: For pdf2image functionality, if the PDF file contains images larger than 1G, it is recommended to process the images using tiled rendering. Otherwise, it may occur exceptions. Following is a brief implementation of tiled rendering.

import os

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

site.addsitedir(‘../../../‘)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Parse page.

page.StartParse(PDFPage.e_ParsePageNormal, None, False)

width = int(page.GetWidth())

height = int(page.GetHeight())

render_sum = 10

width_scale = 1

height_scale = 1

little_width = width * width_scale

little_height = height / render_sum * height_scale

for i in range(0, render_sum):

# According to Matrix, do module rendering for large PDF files.

matrix = page.GetDisplayMatrix(0, -1 * i * little_height, little_width, height * height_scale, page.GetRotation())

# Prepare a bitmap for rendering.

bitmap = Bitmap(little_width, little_height, Bitmap.e_DIBArgb)

bitmap.FillRect(0xFFFFFFFF, None)

render = Renderer(bitmap, False)

render.StartRender(page, matrix, None)

# The bitmap data will be added to the end of image file after rendering.

How to convert an image file to PDF file

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

#replace with the python2 lib path

site.addsitedir(‘../../../‘)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

image = Image(input_file)

count = image.GetFrameCount()

doc = PDFDoc()

for i in range(0, count):

page = doc.InsertPage(i)

page.StartParse(PDFPage.e_ParsePageNormal, None, False)

# Add image to page.

page.AddImage(image, i, PointF(0, 0), page.GetWidth(), page.GetHeight(), True)

doc.SaveAs(output_file, PDFDoc.e_SaveFlagNoOriginal)

Watermark

Watermark is a type of PDF annotation and is widely used in PDF document. Watermark is a visible embedded overlay on a document consisting of text, a logo, or a copyright notice. The purpose of a watermark is to identify the work and discourage its unauthorized use. Foxit PDF SDK provides APIs to work with watermark, allowing applications to create, insert, release and remove watermarks.

Example:

How to create a text watermark and insert it into the first page

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

#replace with the python2 lib path

site.addsitedir(‘../../../‘)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Assuming PDFDoc doc has been loaded.

settings = WatermarkSettings()

settings.flags = WatermarkSettings.e_FlagASPageContents | WatermarkSettings.e_FlagOnTop

settings.offset_x = 0

settings.offset_y = 0

settings.opacity = 90

settings.position = e_PosTopRight

settings.rotation = 45.0

settings.scale_x = 1.0

settings.scale_y = 1.0

text_properties = WatermarkTextProperties()

text_properties.alignment = e_AlignmentCenter

text_properties.color = 0xF68C21

text_properties.font_style = WatermarkTextProperties.e_FontStyleNormal

text_properties.line_space = 1

text_properties.font_size = 12.0

text_properties.font = Font(Font.e_StdIDTimesB)

watermark = Watermark(doc, Foxit PDF SDK\nwww.foxitsoftware.com“, text_properties, settings)

watermark.InsertToPage(doc.GetPage(0))

# Save document to file

How to create an image watermark and insert it into the first page

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

#replace with the python2 lib path

site.addsitedir(‘../../../‘)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Assuming PDFDoc doc has been loaded.

settings = WatermarkSettings()

settings.flags = WatermarkSettings.e_FlagASPageContents | WatermarkSettings.e_FlagOnTop

settings.offset_x = 0.0

settings.offset_y = 0.0

settings.opacity = 20

settings.position = e_PosCenter

settings.rotation = 0.0

image = Image(image_file)

bitmap = image.GetFrameBitmap(0)

settings.scale_x = page.GetWidth() * 0.618 / bitmap.GetWidth()

settings.scale_y = settings.scale_x

watermark = Watermark(doc, image, 0, settings)

watermark.InsertToPage(doc.GetPage(0))

# Save document to file.

How to remove all watermarks from a page

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

#replace with the python2 lib path

site.addsitedir(‘../../../‘)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Assuming PDFPage page has been loaded and parsed.

page.RemoveAllWatermarks()

# Save document to file

Barcode

A barcode is an optical machine-readable representation of data relating to the object to which it is attached. Originally barcodes systematically represented data by varying the widths and spacing of parallel lines, and may be referred to as linear or one-dimensional (1D). Later they evolved into rectangles, dots, hexagons and other geometric patterns in two dimensions (2D). Although 2D systems use a variety of symbols, they are generally referred to as barcodes as well. Barcodes originally were scanned by special optical scanners called barcode readers. Later, scanners and interpretive software became available on devices including desktop printers and smartphones. Foxit PDF SDK provides applications to generate a barcode bitmap from a given string. The barcode types that Foxit PDF SDK supports are listed in Table 3-2.

Table 32

Barcode Type Code39 Code128 EAN8 UPCA EAN13 ITF PDF417 QR
Dimension 1D 1D 1D 1D 1D 1D 2D 2D

Example:

How to generate a barcode bitmap from a string

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

#replace with the python2 lib path

site.addsitedir(‘../../../‘)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Strings used as barcode content.

sz_code_string = TEST-SHEET

# Barcode format types.

code_format = Barcode.e_FormatCode39

#Format error correction level of QR code.

sz_qr_level = Barcode.e_QRCorrectionLevelLow

#Image names for the saved image files for QR code.

bmp_qr_name = /QR_CODE_TestForBarcodeQrCode_L.bmp

# Unit width for barcode in pixels, preferred value is 1-5 pixels.

unit_width = 2

# Unit height for barcode in pixels, preferred value is >= 20 pixels.

unit_height = 120

barcode = Barcode()

bitmap = barcode.GenerateBitmap(sz_code_string, code_format, unit_width, unit_height, sz_qr_level)

Security

Foxit PDF SDK provides a range of encryption and decryption functions to meet different level of document security protection. Users can use regular password encryption and certificate-driven encryption, or using their own security handler for custom security implementation. It also provides APIs to integrate with the third-party security mechanism (Microsoft RMS). These APIs allow developers to work with the Microsoft RMS SDK to both encrypt (protect) and decrypt (unprotect) PDF documents.

Note: For more detailed information about the RMS encryption and decryption, please refer to the simple demo “security” in the “\examples\simple_demo” folder of the download package.

Example:

How to encrypt a PDF file with Certificate

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

#replace with the python2 lib path

site.addsitedir(‘../../../‘)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

doc = PDFDoc(input_file)

error_code = doc.Load()

if error_code != e_ErrSuccess:

return False

# Do encryption.

envelopes = StringArray()

initial_key = “”

cert_file_path = input_path + foxit.cer

if not GetCertificateInfo(cert_file_path, envelopes, initial_key, True, 16):

return False

handler = CertificateSecurityHandler()

encrypt_data = CertificateEncryptData(True, SecurityHandler.e_CipherAES, envelopes)

handler.Initialize(encrypt_data, initial_key)

doc.SetSecurityHandler(handler)

output_file = output_directory + certificate_encrypt.pdf

doc.SaveAs(output_file, PDFDoc.e_SaveFlagNoOriginal)

How to encrypt a PDF file with Foxit DRM

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

#replace with the python2 lib path

site.addsitedir(‘../../../‘)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

doc = PDFDoc(input_file)

error_code = doc.Load()

if error_code != e_ErrSuccess:

return False

# Do encryption.

handler = DRMSecurityHandler()

file_id = Simple-DRM-file-ID

initialize_key = Simple-DRM-initialize-key

encrypt_data = DRMEncryptData(True, Simple-DRM-filter“, SecurityHandler.e_CipherAES, 16, true, 0xfffffffc)

handler.Initialize(encrypt_data, file_id, initialize_key)

doc.SetSecurityHandler(handler)

output_file = output_directory + foxit_drm_encrypt.pdf

doc.SaveAs(output_file, PDFDoc.e_SaveFlagNoOriginal)

Reflow

Reflow is a function that rearranges page content when the page size changes. It is useful for applications that have output devices with difference sizes. Reflow frees the applications from considering layout for different devices. This function provides APIs to create, render, release and access properties of ‘reflow’ pages.

Example:

How to create a reflow page and render it to a bmp file

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

#replace with the python2 lib path

site.addsitedir(‘../../../‘)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Assuming PDFDoc doc has been loaded.

page = doc.GetPage(0)

# Parse PDF page.

page.StartParse(PDFPage.e_ParsePageNormal, None, False)

reflow_page = ReflowPage(page)

# Set some arguments used for parsing the reflow page.

reflow_page.SetLineSpace(0)

reflow_page.SetZoom(100)

reflow_page.SetParseFlags(ReflowPage.e_Normal)

# Parse reflow page.

reflow_page.StartParse(None)

# Get actual size of content of reflow page. The content size does not contain the margin.

content_width = reflow_page.GetContentWidth()

content_height = reflow_page.GetContentHeight()

# Assuming Bitmap bitmap has been created.

# Render reflow page.

renderer = Renderer(bitmap, False)

matrix = reflow_page.GetDisplayMatrix(0, 0)

renderer.StartRenderReflowPage(reflow_page, matrix, None)

Asynchronous PDF

Asynchronous PDF technique is a way to access PDF pages without loading the whole document when it takes a long time. It’s especially designed for accessing PDF files on internet. With asynchronous PDF technique, applications do not have to wait for the whole PDF file to be downloaded before accessing it. Applications can open any page when the data of that page is available. It provides a convenient and efficient way for web reading applications. For how to open and parse pages with asynchronous mode, you can refer to the simple demo “async_load” in the “\examples\simple_demo” folder of the download package.

Pressure Sensitive Ink

Pressure Sensitive Ink (PSI) is a technique to obtain varying electrical outputs in response to varying pressure or force applied across a layer of pressure sensitive devices. In PDF, PSI is usually used for hand writing signatures. PSI data are collected by touching screens or handwriting on boards. PSI data contains coordinates and canvas of the operating area which can be used to generate appearance of PSI. Foxit PDF SDK allows applications to create PSI, access properties, operate on ink and canvas, and release PSI.

Example:

How to create a PSI and set the related properties for it

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

#replace with the python2 lib path

site.addsitedir(‘../../../‘)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

psi = PSI(480, 180, True)

# Set ink diameter.

psi.SetDiameter(9)

# Set ink color.

psi.SetColor(0x434236)

# Set ink opacity.

psi.SetOpacity(0.8)

# Add points to pressure sensitive ink.

x = 121.3043

y = 326.6846

pressure = 0.0966

type = Path.e_TypeMoveTo

psi.AddPoint(PointF(x, y), type, pressure)

Wrapper

Wrapper provides a way for users to save their own data related to a PDF document. For example, when opening an encrypted unauthorized PDF document, users may get an error message. In this case, users can still access wrapper data even when they do not have permissions to the PDF content. The wrapper data could be used to provide information like where to get decryption method of this document.

Example:

How to open a document including wrapper data

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

#replace with the python2 lib path

site.addsitedir(‘../../../‘)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# file_name is PDF document which includes wrapper data.

doc = PDFDoc(file_name)

code = doc.Load()

if code != e_ErrSuccess:

return False

if not doc.IsWrapper():

return False

offset = doc.GetWrapperOffset()

file_reader = FileReader(offset)

file_reader.LoadFile(file_name)

PDF Objects

There are eight types of objects in PDF: Boolean object, numerical object, string object, name object, array object, dictionary object, stream object and null object. PDF objects are document level objects that are different from page objects (see 3.24) which are associated with a specific page each. Foxit PDF SDK provides APIs to create, modify, retrieve and delete these objects in a document.

Example:

How to remove some properties from catalog dictionary

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

#replace with the python2 lib path

site.addsitedir(‘../../../‘)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Assuming PDFDoc doc has been loaded.

catalog = doc.GetCatalog()

if catalog is None:

return

key_strings = (“Type“, Boolean“, Name“, String“, Array“, Dict“)

for key_string in key_strings:

if catalog.HasKey(key_string):

catalog.RemoveAt(key_string)

Page Object

Page object is a feature that allows novice users having limited knowledge of PDF objects (see 3.23 for details of PDF objects) to be able to work with text, path, image, and canvas objects. Foxit PDF SDK provides APIs to add and delete PDF objects in a page and set specific attributes. Using page object, users can create PDF page from object contents. Other possible usages of page object include adding headers and footers to PDF documents, adding an image logo to each page, or generating a template PDF on demand.

Example:

How to create a text object in a PDF page

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

#replace with the python2 lib path

site.addsitedir(‘../../../‘)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Assuming PDFPage page has been loaded and parsed.

position = page.GetLastGraphicsObjectPosition(GraphicsObject.e_TypeText)

text_object = TextObject.Create()

text_object.SetFillColor(0xFFFF7F00)

# Prepare text state.

state = TextState()

state.font_size = 80.0

state.font = Font(“Simsun“, Font.e_StylesSmallCap, Font.e_CharsetGB2312, 0)

state.textmode = TextState.e_ModeFill

text_object.SetTextState(page, state, False, 750)

# Set text.

text_object.SetText(“Foxit Software“)

last_position = page.InsertGraphicsObject(position, text_object)

How to add an image logo to a PDF page

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

#replace with the python2 lib path

site.addsitedir(‘../../../‘)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Assuming PDFPage page has been loaded and parsed.

position = page.GetLastGraphicsObjectPosition(GraphicsObject.e_TypeImage)

image = Image(image_file)

image_object = ImageObject.Create(page.GetDocument())

image_object.SetImage(image, 0)

width = float(image.GetWidth())

height = float(image.GetHeight())

page_width = float(page.GetWidth())

page_height = float(page.GetHeight())

# Please notice the matrix value.

image_object.SetMatrix(Matrix2D(width, 0, 0, height, (page_width width) / 2.0, (page_height height) / 2.0))

page.InsertGraphicsObject(position, image_object)

page.GenerateContent()

content

In PDF document, a portion of content can be marked as marked content element. Marked content helps to organize the logical structure information in a PDF document and enables stylized tagged PDF. Tagged PDF has a standard structure types and attributes that allow page content to be extracted and reused for other purposes. More details about marked content could be found in chapter 10.5 of PDF reference 1.7 [1].

Example:

How to get marked content in a page and get the tag name

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

#replace with the python2 lib path

site.addsitedir(‘../../../‘)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Assuming PDFPage page has been loaded and parsed.

position = page.GetFirstGraphicsObjectPosition(GraphicsObject.e_TypeText)

text_obj = page.GetGraphicsObject(position)

content = text_obj.GetMarkedContent()

item_count = content.GetItemCount()

# Get marked content property

for i in range(0, item_count):

tag_name = content.GetItemTagName(i)

mcid = content.GetItemMCID(i)

Layer

PDF Layers, in other words, Optional Content Groups (OCG), are supported in Foxit PDF SDK. Users can selectively view or hide the contents in different layers of a multi-layer PDF document. Multi-layers are widely used in many application domains such as CAD drawings, maps, layered artwork and multi-language document, etc.

In Foxit PDF SDK, a PDF layer is associated with a layer node. To retrieve a layer node, user should construct a PDF LayerTree object first and then call function LayerTree.GetRootNode to get the root layer node of the whole layer tree. Furthermore, you can enumerate all the nodes in the layer tree from the root layer node. Foxit PDF SDK provides APIs to get/set layer data, view or hide the contents in different layers, set layers’ name, add or remove layers, and edit layers.

Example:

How to create a PDF layer

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

#replace with the python2 lib path

site.addsitedir(‘../../../‘)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Assuming PDFDoc doc has been loaded.

layertree = LayerTree(doc)

root = layertree.GetRootNode()

if root.IsEmpty():

print(“No layer information!\r\n”)

return

How to set all the layer nodes information

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

#replace with the python2 lib path

site.addsitedir(‘../../../‘)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Assuming PDFDoc doc has been loaded.

def SetAllLayerNodesInformation(layer_node):

if layer_node.HasLayer():

layer_node.SetDefaultVisible(True)

layer_node.SetExportUsage(LayerTree.e_StateUndefined)

layer_node.SetViewUsage(LayerTree.e_StateOFF)

print_data = LayerPrintData(“subtype_print“, LayerTree.e_StateON)

layer_node.SetPrintUsage(print_data)

zoom_data = LayerZoomData(1, 10)

layer_node.SetZoomUsage(zoom_data)

new_name = [View_OFF_Print_ON_Export_Undefined] + layer_node.GetName()

layer_node.SetName(new_name)

count = layer_node.GetChildrenCount()

for i in range(0, count):

child = layer_node.GetChild(i)

SetAllLayerNodesInformation(child)

layertree = LayerTree(doc)

root = layertree.GetRootNode()

SetAllLayerNodesInformation(root)

How to edit layer tree

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

#replace with the python2 lib path

site.addsitedir(‘../../../‘)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Assuming PDFDoc doc has been loaded.

# edit layer tree

doc = PDFDoc(input_file)

error_code = doc.Load(“”)

layertree = LayerTree(doc)

root = layertree.GetRootNode()

children_count = root.GetChildrenCount()

root.RemoveChild(children_count 1)

child = root.GetChild(children_count 2)

child0 = root.GetChild(0)

child.MoveTo(child0, 0)

child.AddChild(0, AddedLayerNode“, True)

child.AddChild(0, AddedNode“, False)

Signature

PDF Signature module can be used to create and sign digital signatures for PDF documents, which protects the security of documents’ contents and avoids it to be tampered maliciously. It can let the receiver make sure that the document is released by the signer and the contents of the document are complete and unchanged. Foxit PDF SDK provides APIs to create digital signature, verify the validity of signature, delete existing digital signature, get and set properties of digital signature, display signature and customize the appearance of the signature form fields.

Note: Foxit PDF SDK provides default Signature callbacks which supports the following two types of signature filter and subfilter:

(1) filter: Adobe.PPKLite subfilter: adbe.pkcs7.detached

(2) filter: Adobe.PPKLite subfilter: adbe.pkcs7.sha1

If you use one of the above signature filter and subfilter, you can sign a PDF document and verify the validity of signature by default without needing to register a custom callback.

Example:

How to sign the PDF document with a signature

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

#replace with the python2 lib path

site.addsitedir(‘../../../‘)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

filter = Adobe.PPKLite

sub_filter = adbe.pkcs7.detached

if not use_default:

sub_filter = adbe.pkcs7.sha1

sig_callback = SignatureCallbackImpl(sub_filter)

Library.RegisterSignatureCallback(filter, sub_filter, sig_callback)

print(

Use signature callback object for filter \”{}\” and sub-filter \”{}\”\r\n”

.format(filter, sub_filter))

pdf_page = pdf_doc.GetPage(0)

# Add a new signature to first page.

new_signature = AddSiganture(pdf_page, sub_filter)

# Set filter and subfilter for the new signature.

new_signature.SetFilter(filter)

new_signature.SetSubFilter(sub_filter)

is_signed = new_signature.IsSigned()

sig_state = new_signature.GetState()

print(“[Before signing] Signed?:{}\t State:{}\r\n”.format(

true if is_signed else false“,

TransformSignatureStateToString(sig_state)))

# Sign the new signature.

signed_pdf_path = output_directory + signed_newsignature.pdf

if use_default:

signed_pdf_path = output_directory + signed_newsignature_default_handle.pdf

cert_file_path = input_path + foxit_all.pfx

cert_file_password = 123456

# Cert file path will be passed back to application through callback function FSSignatureCallback.Sign().

# In this demo, the cert file path will be used for signing in callback function FSSignatureCallback.Sign().

new_signature.StartSign(cert_file_path, cert_file_password,

Signature.e_DigestSHA1, signed_pdf_path)

print(“[Sign] Finished!\r\n”)

is_signed = new_signature.IsSigned()

sig_state = new_signature.GetState()

print(“[After signing] Signed?:{}\tState:{}\r\n”.format(

true if is_signed else false“,

TransformSignatureStateToString(sig_state)))

# Open the signed document and verify the newly added signature (which is the last one).

print(“Signed PDF file: {}\r\n”.format(signed_pdf_path))

signed_pdf_doc = PDFDoc(signed_pdf_path)

error_code = signed_pdf_doc.Load(“”)

if e_ErrSuccess != error_code:

print(“Fail to open the signed PDF file.\r\n”)

return

# Get the last signature which is just added and signed.

sig_count = signed_pdf_doc.GetSignatureCount()

signed_signature = signed_pdf_doc.GetSignature(sig_count 1)

# Verify the intergrity of signature.

signed_signature.StartVerify(“”, None)

print(“[Verify] Finished!\r\n”)

is_signed = signed_signature.IsSigned()

sig_state = signed_signature.GetState()

print(“[After verifying] Signed?:{}\tState:{}\r\n”.format(

true if is_signed else false“,

TransformSignatureStateToString(sig_state)))

How to implement signature callback function of signing

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

#replace with the python2 lib path

site.addsitedir(‘../../../‘)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Implementation of pdf.SignatureCallback

class SignatureCallbackImpl(SignatureCallback):

def __init__(self, *args):

if _PYTHON2_:

super(SignatureCallbackImpl, self).__init__()

else:

super().__init__()

self.digest_context_ = None

self.sub_filter_ = args[0]

def __del__(self):

self.__disown__()

def Release(self):

pass

def GetTextFromFile(self, *args):

file_buffer = None

if self.digest_context_ is None or not self.digest_context_.GetFileReadCallback(

):

return False, None

file_read = self.digest_context_.GetFileReadCallback()

val, buffer = file_read.ReadBlock(

(self.digest_context_.GetByteRangeElement(0),

self.digest_context_.GetByteRangeElement(1)))

file_buffer = buffer

val, buffer = file_read.ReadBlock(

(self.digest_context_.GetByteRangeElement(2),

self.digest_context_.GetByteRangeElement(3)))

file_buffer += buffer

return True, file_buffer

def StartCalcDigest(self, *args):

file = args[0]

byte_range_array = args[1]

size_of_array = len(args[1])

signature = args[2]

client_data = args[3]

self.digest_context_ = DigestContext(file, byte_range_array,

size_of_array)

return self.digest_context_.HashInit()

def ContinueCalcDigest(self, *args):

try:

if self.digest_context_ is None:

return Progressive.e_Error

ret, file_buffer = self.GetTextFromFile()

if not ret:

return Progressive.e_Error

self.digest_context_.HashUpdate(file_buffer)

return Progressive.e_Finished

except Exception as ex:

print(ex.GetMessage())

return Progressive.e_Error

def GetDigest(self, *args):

try:

if self.digest_context_ is None:

return “”

digest = self.digest_context_.HashDigest()

return digest

except Exception as ex:

print(ex.GetMessage())

return “”

def Sign(self, *args):

try:

digest = args[0][0]

digest_length = args[0][1]

cert_path = args[1]

password = args[2]

digest_algorithm = args[3]

client_data = args[4]

if self.digest_context_ is None:

return “”

plain_text = “”

if adbe.pkcs7.sha1 == self.sub_filter_:

plain_text = digest

pk12 = crypto.load_pkcs12(open(cert_path, rb‘).read(), password)

pkey = pk12.get_privatekey()

signcert = pk12.get_certificate()

PKCS7_NOSIGS = 0x4

bio_in = crypto._new_mem_buf(plain_text)

pkcs7 = crypto._lib.PKCS7_sign(signcert._x509, pkey._pkey,

crypto._ffi.NULL, bio_in,

PKCS7_NOSIGS)

bio_out = crypto._new_mem_buf()

crypto._lib.i2d_PKCS7_bio(bio_out, pkcs7)

signed_data = crypto._bio_to_string(bio_out)

return signed_data

except Exception as ex:

print(ex.GetMessage())

return “”

def VerifySigState(self, *args):

# Usually, the content of a signature field is contain the certification of signer.

# But we can’t judge this certification is trusted.

# For this example, the signer is ourself. So when using api PKCS7_verify to verify,

# we pass NULL to it’s parameter <i>certs</i>.

# Meanwhile, if application should specify the certificates, we suggest pass flag PKCS7_NOINTERN to

# api PKCS7_verify.

if self.digest_context_ is None:

return Signature.e_StateVerifyErrorData

plain_text = “”

digest = args[0][0]

digest_length = args[0][1]

signed_data = args[1][0]

signed_data_len = args[1][1]

client_data = args[2]

if adbe.pkcs7.sha1 != self.sub_filter_:

return Signature.e_StateUnknown

p7 = crypto.load_pkcs7_data(crypto.FILETYPE_ASN1, signed_data)

PKCS7_NOVERIFY = 0x20

p7bio = crypto._new_mem_buf(digest)

res = crypto._lib.PKCS7_verify(p7._pkcs7, crypto._ffi.NULL,

crypto._ffi.NULL, p7bio,

crypto._ffi.NULL, PKCS7_NOVERIFY)

if res:

return Signature.e_StateVerifyNoChange

else:

return Signature.e_StateVerifyChange

def IsNeedPadData(self, *args):

return False

def CheckCertificateValidity(self, *args):

# User can check the validity of input certificate here.

# If no need to check, just return e_CertValid.

return SignatureCallback.e_CertValid

Long term validation (LTV)

From version 7.0, Foxit PDF SDK provides APIs to establish long term validation of signatures, which is mainly used to solve the verification problem of signatures that have already expired. LTV requires DSS (Document Security Store) which contains the verification information of the signatures, as well as DTS (Document Timestamp Signature) which belongs to the type of time stamp signature.

In order to support LTV, Foxit PDF SDK provides:

Support for adding the signatures of time stamp type, and provides a default signature callback for the subfilter “ETSI.RFC3161”.

TimeStampServerMgr and TimeStampServer classes, which are used to set and manager the server for time stamp. The default signature callback for the subfilter “ETSI.RFC3161” will use the default time stamp server.

LTVVerifier class which offers the functionalities of verifying signatures and adding DSS information to documents. It also provides a basic default RevocationCallback which is required by LTVVerifier.

Following lists an example about how to establish long term validation of signatures using the default signature callback for subfilter “ETSI.RFC3161” and the default RevocationCallback. For more details, please refer to the simple demo “ltv” in the “\examples\simple_demo” folder of the download package.

Example:

How to establish long term validation of signatures using the default signature callback for subfilter “ETSI.RFC3161” and the default RevocationCallback

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

#replace with the python2 lib path

site.addsitedir(‘../../../‘)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Implementation of pdf.SignatureCallback

class SignatureCallbackImpl(SignatureCallback):

def __init__(self, *args):

if _PYTHON2_:

super(SignatureCallbackImpl, self).__init__()

else:

super().__init__()

self.digest_context_ = None

self.sub_filter_ = args[0]

def __del__(self):

self.__disown__()

def Release(self):

pass

def GetTextFromFile(self, *args):

file_buffer = None

if self.digest_context_ is None or not self.digest_context_.GetFileReadCallback(

):

return False, None

file_read = self.digest_context_.GetFileReadCallback()

val, buffer = file_read.ReadBlock(

(self.digest_context_.GetByteRangeElement(0),

self.digest_context_.GetByteRangeElement(1)))

file_buffer = buffer

val, buffer = file_read.ReadBlock(

(self.digest_context_.GetByteRangeElement(2),

self.digest_context_.GetByteRangeElement(3)))

file_buffer += buffer

return True, file_buffer

def StartCalcDigest(self, *args):

file = args[0]

byte_range_array = args[1]

size_of_array = len(args[1])

signature = args[2]

client_data = args[3]

self.digest_context_ = DigestContext(file, byte_range_array,

size_of_array)

return self.digest_context_.HashInit()

def ContinueCalcDigest(self, *args):

try:

if self.digest_context_ is None:

return Progressive.e_Error

ret, file_buffer = self.GetTextFromFile()

if not ret:

return Progressive.e_Error

self.digest_context_.HashUpdate(file_buffer)

return Progressive.e_Finished

except Exception as ex:

print(ex.GetMessage())

return Progressive.e_Error

def GetDigest(self, *args):

try:

if self.digest_context_ is None:

return “”

digest = self.digest_context_.HashDigest()

return digest

except Exception as ex:

print(ex.GetMessage())

return “”

def Sign(self, *args):

try:

digest = args[0][0]

digest_length = args[0][1]

cert_path = args[1]

password = args[2]

digest_algorithm = args[3]

client_data = args[4]

if self.digest_context_ is None:

return “”

plain_text = “”

if adbe.pkcs7.sha1 == self.sub_filter_:

plain_text = digest

pk12 = crypto.load_pkcs12(open(cert_path, rb‘).read(), password)

pkey = pk12.get_privatekey()

signcert = pk12.get_certificate()

PKCS7_NOSIGS = 0x4

bio_in = crypto._new_mem_buf(plain_text)

pkcs7 = crypto._lib.PKCS7_sign(signcert._x509, pkey._pkey,

crypto._ffi.NULL, bio_in,

PKCS7_NOSIGS)

bio_out = crypto._new_mem_buf()

crypto._lib.i2d_PKCS7_bio(bio_out, pkcs7)

signed_data = crypto._bio_to_string(bio_out)

return signed_data

except Exception as ex:

print(ex.GetMessage())

return “”

def VerifySigState(self, *args):

# Usually, the content of a signature field is contain the certification of signer.

# But we can’t judge this certification is trusted.

# For this example, the signer is ourself. So when using api PKCS7_verify to verify,

# we pass NULL to it’s parameter <i>certs</i>.

# Meanwhile, if application should specify the certificates, we suggest pass flag PKCS7_NOINTERN to

# api PKCS7_verify.

if self.digest_context_ is None:

return Signature.e_StateVerifyErrorData

plain_text = “”

digest = args[0][0]

digest_length = args[0][1]

signed_data = args[1][0]

signed_data_len = args[1][1]

client_data = args[2]

if adbe.pkcs7.sha1 != self.sub_filter_:

return Signature.e_StateUnknown

p7 = crypto.load_pkcs7_data(crypto.FILETYPE_ASN1, signed_data)

PKCS7_NOVERIFY = 0x20

p7bio = crypto._new_mem_buf(digest)

res = crypto._lib.PKCS7_verify(p7._pkcs7, crypto._ffi.NULL,

crypto._ffi.NULL, p7bio,

crypto._ffi.NULL, PKCS7_NOVERIFY)

if res:

return Signature.e_StateVerifyNoChange

else:

return Signature.e_StateVerifyChange

def IsNeedPadData(self, *args):

return False

def CheckCertificateValidity(self, *args):

# User can check the validity of input certificate here.

# If no need to check, just return e_CertValid.

return SignatureCallback.e_CertValid

PAdES

From version 7.0, Foxit PDF SDK also supports PAdES (PDF Advanced Electronic Signature) which is the application for CAdES signature in the field of PDF. CAdES is a new standard for advanced digital signature, its default subfilter is “ETSI.CAdES.detached”. PAdES signature includes four levels: B-B, B-T, B-LT, and B-LTA.

B-B: Must include the basic attributes.

B-T: Must include document time stamp or signature time stamp to provide trusted time for existing signatures, based on B-B.

B-LT: Must include DSS/VRI to provide certificates and revocation information, based on B-T.

B-LTA: Must include the trusted time DTS for existing revocation information, based on B-LT.

Foxit PDF SDK provides a default signature callback for the subfilter “ETSI.CAdES.detached” to sign and verify the signatures (with subfilter “ETSI.CAdES.detached”). It also provides TimeStampServerMgr and TimeStampServer classes to set and manager the server for time stamp. The default signature callback for the subfilter “ETSI.CAdES.detached” will use the default time stamp server.

Foxit PDF SDK provides functions to get the level of PAdES from signature, and application level can also judge and determine the level of PAdES according to the requirements of each level. For more details about how to add, sign and verify a PAdES signature in PDF document, please refer to the simple demo “pades” in the “\examples\simple_demo” folder of the download package.

PDF Action

PDF Action is represented as the base PDF action class. Foxit PDF SDK provides APIs to create a series of actions and get the action handlers, such as embedded goto action, JavaScript action, named action and launch action, etc.

Example:

How to create a URI action and insert to a link annot

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

# replace with the python2 lib path

site.addsitedir(‘../../../’)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Assuming PDFPage page has been loaded and parsed.

# Assuming the annnots in the page have been loaded.

# Add link annotation

link = Link(page.AddAnnot(Annot.e_Link, RectF(350,350,380,400)))

link.SetHighlightingMode(Annot.e_HighlightingToggle)

# Add action for link annotation

action = URIAction(Action.Create(page.GetDocument(), Action.e_TypeURI))

action.SetTrackPositionFlag(True)

action.SetURI(“www.foxitsoftware.com“)

link.SetAction(action)

# Appearance should be reset.

link.ResetAppearanceStream()

How to create a GoTo action and insert to a link annot

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

# replace with the python2 lib path

site.addsitedir(‘../../../’)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Assuming the PDFDoc doc has been loaded.

# Assuming PDFPage page has been loaded and parsed.

# Add link annotation

link = Link(page.AddAnnot(Annot.e_Link, RectF(350,350,380,400)))

link.SetHighlightingMode(Annot.e_HighlightingToggle)

action = Action.Create(page.GetDocument(), Action.e_TypeGoto)

newDest = Destination.CreateXYZ(page.GetDocument(), 0,0,0,0)

action.SetDestination(newDest)

JavaScript

JavaScript was created to offload Web page processing from a server onto a client in Web-based applications. Foxit PDF SDK JavaScript implements extensions, in the form of new objects and their accompanying methods and properties, to the JavaScript language. It enables a developer to manage document security, communicate with a database, handle file attachments, and manipulate a PDF file so that it behaves as an interactive, web-enabled form, and so on.

JavaScript action is an action that causes a script to be compiled and executed by the JavaScript interpreter. Class JavaScriptAction is derived from Action and offers functions to get/set JavaScript action data.

The JavaScript methods and properties supported by Foxit PDF SDK are listed in the appendix.

Example:

How to add JavaScript Action to Document

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

# replace with the python2 lib path

site.addsitedir(‘../../../’)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Load Document doc.

javascript_action = JavaScriptAction(Action.Create(doc, Action.e_TypeJavaScript))

javascript_action.SetScript(“app.alert(\”Hello Foxit \”);“)

additional_act = AdditionalAction(doc)

additional_act.SetAction(AdditionalAction.e_TriggerDocWillClose,javascript_action)

additional_act.DoJSAction(AdditionalAction.e_TriggerDocWillClose)

How to add JavaScript Action to Annotation

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

# replace with the python2 lib path

site.addsitedir(‘../../../’)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Load Document and get a widget annotation.

javascript_action = JavaScriptAction(Action.Create(page.GetDocument(), Action.e_TypeJavaScript))

javascript_action.SetScript(“app.alert(\”Hello Foxit \”);“)

additional_act = AdditionalAction(annot)

additional_act.SetAction(AdditionalAction.e_TriggerAnnotMouseButtonPressed, javascript_action)

additional_act.DoJSAction(AdditionalAction.e_TriggerAnnotMouseButtonPressed)

How to add JavaScript Action to FormField

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

# replace with the python2 lib path

site.addsitedir(‘../../../’)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Load Document and get a form field.

# Add text field

control = form.AddControl(page, Text Field0“, Field.e_TypeTextField, RectF(50, 600, 90, 640))

control.GetField().SetValue(“3“)

# Update text field’s appearance.

control.GetWidget().ResetAppearanceStream()

control1 = form.AddControl(page, “Text Field1”, Field.e_TypeTextField, RectF(100, 600, 140, 640))

control1.GetField().SetValue(“23”)

# Update text field’s appearance.

control1.GetWidget().ResetAppearanceStream()

control2 = form.AddControl(page, Text Field2“, Field.e_TypeTextField, RectF(150, 600, 190, 640))

javascipt_action = JavaScriptAction(Action.Create(form.GetDocument(), Action.e_TypeJavaScript))

javascipt_action.SetScript( AFSimple_Calculate(\”SUM\”, new Array (\”Text Field0\”, \”Text Field1\”))“)

field2 = control2.GetField()

additional_act = AdditionalAction(field2)

additional_act.SetAction(AdditionalAction.e_TriggerFieldRecalculateValue,

javascipt_action)

# Update text field’s appearance.

control2.GetWidget().ResetAppearanceStream()

How to add a new annotation to PDF using JavaScript

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

# replace with the python2 lib path

site.addsitedir(‘../../../’)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Load Document and get form field, construct a Form object and a Filler object.

javascipt_action = JavaScriptAction(Action.Create(form.GetDocument(), Action.e_TypeJavaScript))

javascipt_action.SetScript(“var annot = this.addAnnot({ page : 0, type : \”Square\”, rect : [ 0, 0, 100, 100 ], name : \”UniqueID\”, author : \”A. C. Robat\”, contents : \”This section needs revision.\” }); )

additional_act = AdditionalAction(field)

additional_act.SetAction(AdditionalAction.e_TriggerAnnotCursorEnter,javascipt_action)

additional_act.DoJSAction(AdditionalAction.e_TriggerAnnotCursorEnter)

How to get/set properties of annotations (strokeColor, fillColor, readOnly, rect, type) using JavaScript

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

# replace with the python2 lib path

site.addsitedir(‘../../../’)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Load Document and get form field, construct a Form object and a Filler object.

# Get properties of annotations.

javascipt_action = JavaScriptAction(Action.Create(form.GetDocument(), Action.e_TypeJavaScript))

javascipt_action.SetScript(“var ann = this.getAnnot(0, \” UniqueID \”); if (ann != null) { console.println(\”Found it! type: \” + ann.type); console.println(\”readOnly: \” + ann.readOnly); console.println(\”strokeColor: \” + ann.strokeColor);console.println(\”fillColor: \” + ann.fillColor); console.println(\”rect: \” + ann.rect);}“);

additional_act = AdditionalAction(field)

additional_act.SetAction(AdditionalAction.e_TriggerAnnotCursorEnter,javascipt_action)

additional_act.DoJSAction(AdditionalAction.e_TriggerAnnotCursorEnter)

# Set properties of annotations (only take strokeColor as an example).

javascipt_action1 = JavaScriptAction(Action.Create(form.GetDocument(), Action.e_TypeJavaScript))

javascipt_action1.SetScript(Lvar ann = this.getAnnot(0, \”UniqueID\”);if (ann != null) { ann.strokeColor = color.blue; }“)

additional_act1 = AdditionalAction(field1)

additional_act1.SetAction(AdditionalAction.e_TriggerAnnotCursorEnter,javascipt_action1)

additional_act1.DoJSAction(AdditionalAction.e_TriggerAnnotCursorEnter)

How to destroy annotation using JavaScript

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

# replace with the python2 lib path

site.addsitedir(‘../../../’)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Load Document and get form field, construct a Form object and a Filler object.

javascipt_action = JavaScriptAction(Action.Create(form.GetDocument(), Action.e_TypeJavaScript))

javascipt_action.SetScript(“var ann = this.getAnnot(0, \” UniqueID \”); if (ann != null) { ann.destroy(); } )

additional_act = AdditionalAction(field)

additional_act.SetAction(AdditionalAction.e_TriggerAnnotCursorEnter,javascipt_action)

additional_act.DoJSAction(AdditionalAction.e_TriggerAnnotCursorEnter)

Redaction

Redaction is the process of removing sensitive information while keeping the document’s layout. It allows users to permanently remove (redact) visible text and images from PDF documents to protect confidential information, such as social security numbers, credit card information, product release dates, and so on.

Redaction is a type of markup annotation, which is used to mark some contents of a PDF file and then the contents will be removed once the redact annotations are applied.

To do Redaction, you can use the following APIs:

Call function Redaction.Redaction to create a redaction module. If module “Redaction” is not defined in the license information which is used in function Library.Initialize, it means user has no right in using redaction related functions and this constructor will throw exception e_ErrInvalidLicense.

Then call function Redaction.MarkRedactAnnot to create a redaction object and mark page contents (text object, image object, and path object) which are to be redacted.

Finally call function Redaction.Apply to apply redaction in marked areas: remove the text or graphics under marked areas permanently.

Note: To use the redaction feature, please make sure the license key has the permission of the ‘Redaction’ module.

Example:

How to redact the text “PDF” on the first page of a PDF

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

# replace with the python2 lib path

site.addsitedir(‘../../../’)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

redaction = Redaction(doc)

# Parse PDF page.

page = doc.GetPage(0)

page.StartParse(PDFPage.e_ParsePageNormal, None, False)

text_page = TextPage(page)

text_search = TextSearch(text_page)

text_search.SetPattern(“PDF“)

rect_array = RectFArray()

while text_search.FindNext():

itemArray = text_search.GetMatchRects()

rect_array.InsertAt(rect_array.GetSize(), itemArray)

if rect_array.GetSize() > 0:

redact = redaction.MarkRedactAnnot(page, rect_array)

redact.ResetAppearanceStream()

doc.SaveAs(output_directory + AboutFoxit_redected_default.pdf“)

# Set border color to green.

redact.SetBorderColor(0x00FF00)

# Set fill color to blue.

redact.SetFillColor(0x0000FF)

# Set rollover fill color to red.

redact.SetApplyFillColor(0xFF0000)

redact.ResetAppearanceStream()

doc.SaveAs(output_directory + AboutFoxit_redected_setColor.pdf“)

redact.SetOpacity(0.5)

redact.ResetAppearanceStream()

doc.SaveAs(output_directory + AboutFoxit_redected_setOpacity.pdf“)

if redaction.Apply():

print(“Redact page(0) succeed.“)

else:

print(“Redact page(0) failed.“)

doc.SaveAs(output_directory + AboutFoxit_redected_apply.pdf“)

Comparison

Comparison feature lets you see the differences in two versions of a PDF. Foxit PDF SDK provides APIs to compare two PDF documents page by page, the differences between the two documents will be returned.

The differences can be defined into three types: delete, insert and replace. You can save these differences into a PDF file and mark them as annotations.

Note: To use the comparison feature, please make sure the license key has the permission of the ‘Comparison’ module.

Example:

How to compare two PDF documents and save the differences between them into a PDF file

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

# replace with the python2 lib path

site.addsitedir(‘../../../’)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

base_doc = PDFDoc(input_base_file)

error_code = base_doc.Load(“”)

if error_code != e_ErrSuccess:

print(“The Doc [{}] Error: {}\n”.format(input_base_file, error_code))

return 1

compared_doc = PDFDoc(input_compared_file)

error_code = compared_doc.Load(“”)

if error_code != e_ErrSuccess:

print(“The Doc [{}] Error: {}\n”.format(input_base_file, error_code))

return 1

comparison = Comparison(base_doc, compared_doc)

result = comparison.DoCompare(0, 0, Comparison.e_CompareTypeText)

oldInfo = result.base_doc_results

newInfo = result.compared_doc_results

oldInfoSize = oldInfo.GetSize()

newInfoSize = newInfo.GetSize()

page = compared_doc.GetPage(0)

for i in range(0, newInfoSize):

item = newInfo.GetAt(i)

type = item.type

if type == CompareResultInfo.e_CompareResultTypeDeleteText:

res_string = “\”{}\””.format(item.diff_contents)

CreateDeleteTextStamp(page, item.rect_array, 0xff0000,

res_string, Compare : Delete“, Text“)

elif type == CompareResultInfo.e_CompareResultTypeInsertText:

res_string = “\”{}\””.format(item.diff_contents)

CreateDeleteText(page, item.rect_array, 0x0000ff, res_string,

Compare : Insert“, Text“)

elif type == CompareResultInfo.e_CompareResultTypeReplaceText:

res_string = [Old]: \”{}\”\r\n[New]: \”{}\””.format(

oldInfo.GetAt(i).diff_contents, item.diff_contents)

CreateSquigglyRect(page, item.rect_array, 0xe7651a, res_string,

Compare : Replace“, Text“)

# Save the comparison result to a PDF file.

compared_doc.SaveAs(output_directory + result.pdf“)

Note: for CreateDeleteTextStamp and CreateHighlightRect functions, please refer to the simple demo pdfcompare” located in the “\examples\simple_demo” folder of the download package.

OCR

Optical Character Recognition, or OCR, is a software process that enables images or printed text
to be translated into machine-readable text. OCR is most commonly used when scanning paper
documents to create electronic copies, but can also be performed on existing electronic
documents (e.g. PDF).

From version 9.0, Linux x64 platform supports OCR feature, and the OCR engine has also been upgraded, please contact Foxit support team or sales team to get the latest engine files package.

This section will provide instructions on how to set up your environment for the OCR feature module using Foxit PDF SDK for Windows and Linux.

System requirements

Platform: Windows, Linux (x64)

Programming Language: C, C++, Java, Python, C#

License Key requirement: ‘OCR’ module permission in the license key

SDK Version: Foxit PDF SDK for Windows (C++, Java, C#) 6.4 or higher; Foxit PDF SDK (C) 7.4 or higher; Foxit PDF SDK for Windows (Python) 8.3 or higher; Foxit PDF SDK for Linux x64 (C++, Java, C#, Python) 9.0

Trial limit for SDK OCR add-on module

For the trial version, there are three trail limits that you should notice:

Allow 30 consecutive natural days to evaluate SDK from the first time of OCREngine initialization.

Allow up to 5000 pages to be converted using OCR from the first time of OCREngine initialization.

Trail watermarks will be generated on the PDF pages. This limit is used for all of the SDK modules.

OCR resource files

Please contact Foxit support team or sales team to get the OCR resource files package.

For Windows:

After getting the package for Windows, extract it to a desired directory (for example, extract the package to a directory named “ocr_addon“), and then you can see the resource files for OCR are as follows:

debugging_files: Resource files used for debugging the OCR project. These file(s) cannot be distributed.

language_resource_CJK: Resource files for CJK language, including: Chinese-Simplified, Chinese-Traditional, Japanese, and Korean.

language_resources_noCJK: Resource files for the languages except CJK, including: Basque, Bulgarian, Catalan, Croatian, Czech, Danish, Dutch, English, Estonian, Faeroese, Finnish, French, Galician, German, Greek, Hebrew, Hungarian, Icelandic, Italian, Latvian (Lettish), Lithuanian, Macedonian, Maltese, Norwegian, Polish, Portuguese, Romanian, Russian, Serbian, Slovak, Slovenian, Spanish, Swedish, Thai, Turkish, Ukrainian.

win32_lib: 32-bit library resource files

win64_lib: 64-bit library resource files

readme.txt: A txt file for introducing the role of each folder in this directory, as well as how to use those resource files for OCR.

For Linux x64

After getting the package for Linux, extract it to a desired directory (for example, extract the package to a directory named “ocr_addon_linux“), and then you can see the resource files for OCR are as follows:

Data: Data and resource files for following languages:

Chinese-Simplified, Chinese-Traditional, Japanese, Korean, Basque, Bulgarian, Catalan, Croatian, Czech, Danish, Dutch, English, Estonian, Faeroese, Finnish, French, Galician, German, Greek, Hebrew, Hungarian, Icelandic, Italian, Latvian (Lettish), Lithuanian, Macedonian, Maltese, Norwegian, Polish, Portuguese, Romanian, Russian, Serbian, Slovak, Slovenian, Spanish, Swedish, Thai, Turkish, Ukrainian.

Bin: Library files for Linux64.

How to run the OCR demo

Foxit PDF SDK for Python API (Windows and Linux x64) provides an OCR demo located in the “\examples\simple_demo\ocr” folder to show you how to use Foxit PDF SDK to do OCR for a PDF page or a PDF document.

Build an OCR resource directory

Before running the OCR demo, you should first build an OCR resource directory, and then pass the directory to Foxit PDF SDK API OCREngine.Initialize to initialize OCR engine.

For Windows:

To build an OCR resource directory on Windows, please follow the steps below:

Create a new folder to add the resources. For example, “D:/ocr_resources”.

Add the appropriate library resource based on the platform architecture.

For win32, copy all the files under “ocr_addon/win32_lib” folder to “D:/ocr_resources”.

For win64, copy all the files under “ocr_addon/win64_lib” folder to “D:/ocr_resources”.

Add the language resource.

For CJK (Chinese-Simplified, Chinese-Traditional, Japanese, and Korean), copy all the files under “ocr_addon/language_resource_CJK” folder to “D:/ocr_resources”.

For all other languages except CJK, copy all the files under “ocr_addon/language_resources_noCJK” folder to “D:/ocr_resources”.

For all the supported languages, copy all the files under “ocr_addon/language_resource_CJK” and “ocr_addon/language_resources_noCJK” folders to “D:/ocr_resources”.

(Optional) Add debugging file resource if you need to debug the demo.

For win32, copy the file(s) under “ocr_addon/debugging_files/win32” folder to “D:/ocr_resources”.

For win64, copy the file(s) under “ocr_addon/debugging_files/win64” folder to “D:/ocr_resources”.

Note: The debugging files should be exclusively used for testing purposes. So, you cannot distribute them.

For Linux x64

To build an OCR resource directory on Linux, please follow the steps below:

Create a new folder to add the resources. For example, “/root/Desktop/ocr_resources”.

Copy the whole folders of “Data“, “Bin” under the “ocr_addon_linux” to “/root/Desktop/ocr_resources”.

Then, the OCR resource files path is set to “/root/Desktop/ocr_resources/Bin“.

Note: Before loading the resource files, please set the environment variable for loading the library, please execute: export LD_LIBRARY_PATH=/root/Desktop/ocr_resources/Bin.

Configure the demo

After building the OCR resource directory, configure the demo in the “\examples\simple_demo\ocr\ocr.py” file. Following will configure the demo in “ocr.py” file on Windows for example. For Linux x64 platform, do the similar configuration with Windows.

Specify the OCR resource directory

Add the OCR resource directory as follows, which will be used to initialize the OCR engine.

# “ocr_resource_path” is the path of ocr resources. Please refer to Developer Guide for more details.

ocr_resource_path = D:/ocr_resources

Choose the language resource

You will need to set the language used by the OCR engine into the demo code. This is done with the OCREngine.SetLanguages method and is set to “English” by default.

# Set languages.

OCREngine.SetLanguages(“English”)

(Optional) Set log for OCREngine

If you want to print the entire log of the OCR Engine, please uncomment the OCREngine.SetLogFile method as below:

# Set log for OCREngine. (This can be opened to set log file if necessary)

OCREngine.SetLogFile(output_directory+”ocr.log”)

Run the demo

Once you run the demo successfully by “python -u ocr.py” in the CMD, the console will print the following by default:

The demo will OCR the default document (“\examples\simple_demo\input_files\ocr\AboutFoxit_ocr.pdf”) in four different ways, which will output four different PDFs in the output folder (“\examples\simple_demo\output_files\ocr”):

OCR Editable PDF – ocr_doc_editable.pdf

OCR Searchable PDF – ocr_doc_searchable.pdf

OCR Editable PDF Page – ocr_page_editable.pdf

OCR Searchable PDF Page – ocr_page_searchable.pdf

Compliance

PDF Compliance

Foxit PDF SDK supports to convert PDF versions among PDF 1.3, PDF 1.4, PDF 1.5, PDF 1.6 and PDF 1.7. When converting to PDF 1.3, if the source document contains transparency data, then it will be converted to PDF 1.4 instead of PDF 1.3 (PDF 1.3 does not support transparency). If the source document does not contain any transparency data, then it will be converted to PDF 1.3 as expected.

PDF/A Compliance

PDF/A is an ISO-standardized version of the PDF specialized for use in the archiving and long-term preservation of electronic documents. PDF/A differs from PDF by prohibiting features unsuitable for long-term archiving, such as font linking (as opposed to font embedding), encryption, JavaScript, audio, video and so on.

Foxit PDF SDK provides APIs to convert a PDF to be compliance with PDF/A standard, or verify whether a PDF is compliance with PDF/A standard. It supports the PDF/A version including PDF/A-1a, PDF/A-1b, PDF/A-2a, PDF/A-2b, PDF/A-2u, PDF/A-3a, PDF/A-3b, PDF/A-3u (ISO 19005- 1, 19005 -2 and 19005-3).

This section will provide instructions on how to set up your environment for running the ‘compliance’ demo.

System requirements

Platform: Windows, Linux (x86 and x64), Mac

Programming Language: C, C++, Java, C#, Python, Objective-C

License Key requirement: ‘Compliance’ module permission in the license key

SDK Version: Foxit PDF SDK (C++, Java, C#, Objective-C) 6.4 or higher (for PDF Compliance, it requires Foxit PDF SDK 7.1 or higher); Foxit PDF SDK (C) 7.4 or higher; Foxit PDF SDK (Python) 8.3 or higher

Compliance resource files

Please contact Foxit support team or sales team to get the Compliance resource files package.

After getting the package, extract it to a desired directory (for example, extract the package to a directory: “compliance/win” for Windows, “compliance/linux” for Linux, and “compliance/mac” for Mac), and then you can see the resource files for Compliance are as follows:

For Windows:

For Linux:

For Mac:

How to run the compliance demo

Foxit PDF SDK provides a compliance demo located in the “\examples\simple_demo\compliance” folder to show you how to use Foxit PDF SDK to verify whether a PDF is compliance with PDF/A standard, and convert a PDF to be compliance with PDF/A standard, as well as convert PDF versions.

Build a compliance resource directory

Before running the compliance demo, you should first build a compliance resource directory, and then pass the directory to Foxit PDF SDK API ComplianceEngine.Initialize to initialize compliance engine.

Windows

To build a compliance resource directory on Windows, please follow the steps below:

Create a new folder to add the resources. For example, “D:/compliance_resources”.

Copy the whole folders of “ect“, “lang“, “var” under the “compliance/win” to “D:/compliance_resources”.

Add the appropriate library resource based on the platform architecture.

For win32, copy all the files under “compliance/win/lib/x86” folder to “D:/compliance_resources”.

For win64, copy all the files under “compliance/win/lib/x64” folder to “D:/compliance_resources”.

For example, use win32 platform architecture, then the compliance resource directory should be as follows:

Linux

To build a compliance resource directory on Linux, please follow the steps below:

Create a new folder to add the resources. For example, “/root/Desktop/compliance_resources”.

Copy the whole folders of “ect“, “lang“, “var” under the “compliance/linux” to “/root/Desktop/compliance_resources”.

Add the appropriate library resource based on the platform architecture.

For linux32, copy all the files under “compliance/linux/lib/x86” folder to “/root/Desktop/compliance_resources”.

For linux64, copy all the files under “compliance/linux/lib/x64” folder to “/root/Desktop/compliance_resources”.

For example, use linux32 platform architecture, then the compliance resource directory should be as follows:

Note: For Linux platform, you should put the compliance resource directory into the search path for system shared library before running the demo, otherwise ComplianceEngine.Initialize will fail.

For example, you can use the command (export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}: /root/Desktop/compliance_resources) to temporarily add the compliance resource directory to LD_LIBRARY_PATH.

Mac

For Mac platform, you can directly use the “compliance/mac” resource folder as the compliance resource directory.

Configure the demo

After building the compliance resource directory, configure the demo in the “\examples\simple_demo\compliance\compliance.py” file.

This section takes Windows as an example to show you how to configure the demo in the “compliance.py” file. For Linux and Mac platforms, do the same configuration with Windows.

Specify the compliance resource directory

In the “compliance.py” file, add the compliance resource directory as follows, which will be used to initialize the compliance engine.

# If you use an authorization key for Foxit PDF SDK, please set a valid unlock code string to compliance_engine_unlockcode for ComplianceEngine.

# If you use a trial key for Foxit PDF SDK, just keep compliance_engine_unlockcode as an empty string.

compliance_resource_folder_path = D:/compliance_resources

compliance_engine_unlockcode = “”

# Initialize compliance engine.

error_code = ComplianceEngine.Initialize(compliance_resource_folder_path, compliance_engine_unlockcode)

Note:

If you are using a trial key for Foxit PDF SDK, you do not need to authorize the compliance engine library.

If you are using an authorization key for Foxit PDF SDK, Foxit sales team will send you an extra unlock code for initializing compliance engine library. Pass the unlock code to the initialize function “ComplianceEngine.Initialize(compliance_resource_folder_path, compliance_engine_unlockcode)”.

(Optional) Set language for compliance engine

ComplianceEngine.SetLanguage function is used to set language for compliance engine. The default language is “English”, and the supported languages are as follows:

“Czech”, “Danish”, “Dutch”, “English”, “French”, “Finnish”, “German”, “Italian”, “Norwegian”, “Polish”, “Portuguese”, “Spanish”, “Swedish”, “Chinese-Simplified”, “Chinese-Traditional”, “Japanese”, “Korean”.

For example, set the language to “Chinese-Simplified”.

// Set languages. If not set language to ComplianceEngine, “English” will be used as default.

ComplianceEngine.SetLanguage(“Chinese-Simplified”);

(Optional) Set a temp folder for compliance engine

ComplianceEngine.SetTempFolderPath function is used to set a temp folder to store several files for proper processing (e.g verifying or converting). If no custom temp folder is set by this function, the default temp folder in system will be used.

For example, set the path to “D:/compliance_temp” (should be a valid path).

// Set custom temp folder path for ComplianceEngine.

ComplianceEngine.SetTempFolderPath(L” D:/compliance_temp “);

Run the demo

Once you run the demo successfully by “python -u compliance.py” in the CMD, the console will print the following by default:

The demo will

verify whether the PDF (“\examples\simple_demo\input_files\AboutFoxit.pdf”) is compliance with PDF/A-1a standard, and convert the PDF to be compliance with PDF/A-1a standard.

convert PDF file (“\examples\simple_demo\input_files\AF_ImageXObject_FormXObject.pdf”) to PDF-1.4 and PDF-1.7.

The output files are located in “\examples\simple_demo\output_files\compliance” folder.

Optimization

Optimization feature can reduce the size of PDF files to save disk space and make files easier to send and store, through compressing images, deleting redundant date, discarding useless user data and so on. From version 7.0, optimization module provides functions to compress the color/grayscale/monochrome images in PDF files to reduce the size of the PDF files.

Note: To use the Optimization feature, please make sure the license key has the permission of the ‘Optimization’ module.

Example:

How to optimize PDF files by compressing the color/grayscale/monochrome images

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

# replace with the python2 lib path

site.addsitedir(‘../../../’)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

doc = PDFDoc(input_file)

error_code = doc.Load(“input_pdf_file“)

if error_code != e_ErrSuccess:

print(“The Doc [{}] Error: {}\n”.format(input_file, error_code))

return 1

pause = Optimization_Pause(0, True)

settings = OptimizerSettings()

settings.SetOptimizerOptions(

OptimizerSettings.e_OptimizerCompressImages)

progressive = Optimizer.Optimize(doc, settings, pause)

progress_state = Progressive.e_ToBeContinued

while Progressive.e_ToBeContinued == progress_state:

progress_state = progressive.Continue()

percent = progressive.GetRateOfProgress()

print(“Optimize progress percent: {} %.format(percent))

if Progressive.e_Finished == progress_state:

doc.SaveAs(output_directory + ImageCompression_Optimized.pdf“, PDFDoc.e_SaveFlagRemoveRedundantObjects)

print(“Optimized Finish.“)

HTML to PDF Conversion

For some large HTML files or a webpage which contain(s) many contents, it is not convenient to print or archive them directly. Foxit PDF SDK provides APIs to convert the online webpage or local HTML files like invoices or reports into PDF file(s), which makes them easier to print or archive. In the process of conversion from HTML to PDF, Foxit PDF SDK also supports to create and add PDF Tags based on the organizational structure of HTML.

From version 8.1, the converted files (generated by HTML to PDF) can be provided in the form of file stream. If you want to use this feature, you should contact Foxit support team or sales team to get the latest engine files package.

From version 8.2, the HTML to PDF engine has been upgraded, please contact Foxit support team or sales team to get the latest engine files package.

From version 8.3, the HTML to PDF engine has also been upgraded, please contact Foxit support team or sales team to get the latest engine files package.

From version 8.4.1, the HTML to PDF engine has also been upgraded, please contact Foxit support team or sales team to get the latest engine files package.

This section will provide instructions on how to set up your environment for running the ‘html2pdf’ demo.

System requirements

Platform: Windows, Linux (x86 and x64), Mac

Programming Language: C, C++, Java, C#, Python, Objective-C

License Key requirement: ‘Conversion’ module permission in the license key

SDK Version: Foxit PDF SDK (C++, Java, C#, Objective-C) 7.0 or higher; Foxit PDF SDK (C) 7.4 or higher; Foxit PDF SDK (Python) 8.3 or higher

HTML to PDF engine files

Please contact Foxit support team or sales team to get the HTML to PDF engine files package.

After getting the package, extract it to a desired directory (for example, extract the package to a directory: “D:/htmltopdf/win” for Windows, “htmltopdf/linux” for Linux, and “htmltopdf/mac” for Mac).

How to run the html2pdf demo

Foxit PDF SDK provides a html2pdf demo located in the “\examples\simple_demo\html2pdf” folder to show you how to use Foxit PDF SDK to convert from html to PDF.

Configure the demo

For html2pdf demo, you can configure the demo in the “\examples\simple_demo\html2pdf\html2pdf.py” file, or you can configure the demo with parameters directly in a command prompt or a terminal. Following will configure the demo in “html2pdf.py” file on Windows for example.

Specify the html2pdf engine directory

In the “html2pdf.py” file, add the path of the engine file “fxhtml2pdf.exe” as follows, which will be used to convert html files to PDF files.

# “engine_path” is the path of the engine file “fxhtml2pdf” which is used to convert html to pdf. Please refer to Developer Guide for more details.

engine_path = D:/htmltopdf/win/fxhtml2pdf.exe # engine_path =D:/htmltopdf/win/fxhtml2pdf

(Optional) Specify cookies file path

Add the path of the cookies file exported from the web pages that you want to convert. For example,

# “cookies_path” is the path of the cookies file exported from the web pages that you want to convert. Please refer to Developer Guide for more details.

cookies_path = D:/cookies.txt

Run the demo

Run the demo without parameters

Once you run the demo successfully by “python -u html2pdf.py” in the CMD, the console will print the following by default:

Run the demo with parameters

After building the demo successfully, open a command prompt, navigate to “\examples\simple_demo\html2pdf\ “, type ” python -u html2pdf.py –help” for example to see how to use the parameters to execute the program.

For example, convert the URL web page “www.foxitsoftware.com” into a PDF with setting the page width to 900 points and the page height to 300 points:

The output file is located in “\examples\simple_demo\output_files\html2pdf” folder.

Parameters Description

Basic Syntax:

html2pdf_xxx <-html <The url or html path>> <-o <output pdf path>> <-engine <htmltopdf engine path>>
[-w <page width>] [-h <page height>] [-ml <margin left>] [-mr <margin right>]

[-mt <margin top>] [-mb <margin bottom>] [-r <page rotation degree>] [-mode <page mode>] [-scale <scaling mode>] [-link <whether to convert link>]

[-tag <whether to generate tag>] [-bookmarks <whether to generate bookmarks>]

[-print_background <whether to print background>]

[-optimize_tag <whether to optimize tag tree>] [-media <media style>] [-encoding <HTML encoding format>] [-render_images <Whether to render images>]

[-remove_underline_for_link <Whether to remove underline for link>]

[-headerfooter <Whether to generate headerfooter>] [-headerfooter_title <headerfooter title>] [-headerfooter_url <headerfooter url>] [-bookmark_root_name <bookmark root name>] [-resize_objects <Whether to enable the JavaScripts related resizing of the objects>]

[-cookies <cookies file path>] [-timeout <timeout>] [–help<Parameter usage>]

Note:

<> required

[ ] optional

Parameters Description
–help The usage description of the parameters.
-html The url or html file path. For examples ‘-html www.foxitsoftware.com’.
-o The path of the output PDF file.
-engine The path of the engine file “fxhtml2pdf.exe”.
-w The page width of the output PDF file in points.
-h The page height of the output PDF file in points.
-r The page rotation for the output PDF file. 0 : 0 degree. 1 : 90 degree. 2 : 180 degree. 3 : 270 degree.
-ml The left margin of the pages for the output PDF file.
-mr The right margin of the pages for the output PDF file.
-mt The top margin of the pages for the output PDF file.
-mb The bottom margin of the pages for the output PDF file.
-mode The page mode for the output PDF file. 0 : Single page mode. 1 : Multiple pages mode.
-scale The scaling mode. 0 : No need to scale pages. 1 : Scale pages. 2 : Enlarge page.
-link Whether to convert links. ‘yes’ : Convert links. ‘no’ : No need to convert links.
-tag Whether to generate tag. ‘yes’ : Generate tag. ‘no’ : No need to generate tag.
-bookmarks Whether to generate bookmarks. ‘yes’ : Generate bookmarks . ‘no’ : No need to generate bookmarks.
-print_background Whether to print background. ‘yes’ : Print bookmarks . ‘no’ : No need to print bookmarks.
-optimize_tag Whether to optimize tag tree. ‘yes’ : Optimize tag tree . ‘no’ : No need to optimize tag tree.
-media The media style. 0 : Screen media style. 1 : Print media style.
-encoding The HTML encoding format. 0 : Auto encoding . 1-73 : Other encodings.
-render_images Whether to render images. ‘yes’ : Render images. ‘no’ : No need to render images.
-remove_underline_for_link Whether to remove underline for link. ‘yes’ : Remove underline for link. ‘no’ : No need to remove underline for link.
-headerfooter Whether to generate headerfooter. ‘yes’ : Generate headerfooter. ‘no’ : No need to generate headerfooter.
-headerfooter_title The headerfooter title.
-headerfooter_url The headerfooter url.
-bookmark_root_name The bookmark root name.
-resize_objects Whether to enable the JavaScripts related resizing of the objects during rendering process. ‘yes’ : Enable. ‘no’ : Disable.
-cookies The path of the cookies file exported from a URL that you want to convert.
-timeout The timeout of loading webpages.

How to work with Html2PDF API

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

# replace with the python2 lib path

site.addsitedir(‘../../../’)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

pdf_setting_data = HTML2PDFSettingData()

pdf_setting_data.is_convert_link = True

pdf_setting_data.is_generate_tag = True

pdf_setting_data.to_generate_bookmarks = True

pdf_setting_data.rotate_degrees = e_Rotation0

pdf_setting_data.page_height = 640

pdf_setting_data.page_width = 900

pdf_setting_data.page_mode = HTML2PDFSettingData.e_PageModeSinglePage

pdf_setting_data.scaling_mode = HTML2PDFSettingData.e_ScalingModeScale

pdf_setting_data.to_print_background = True

pdf_setting_data.to_optimize_tag_tree = False

pdf_setting_data.media_style = HTML2PDFSettingData.e_MediaStyleScreen

Convert.FromHTML(url_or_html, engine_path, cookies_path, pdf_setting_data, output_path, time_out)

Office to PDF Conversion

From version 7.3, Foxit PDF SDK provides APIs to convert Microsoft Office documents (Word and Excel) into professional-quality PDF files on Windows platform.

From version 7.4, Foxit PDF SDK also supports to converst PowerPoint documents into PDF files on Windows platform.

From version 8.4, Foxit PDF SDK provides APIs to convert Microsoft Office documents (Word, Excel and PowerPoint) into professional-quality PDF files on Linux platform (x86, x64 and armv8). Foxit PDF SDK for Python API supports Windows and Linux x86/x64 platforms.

For using this feature, please note that:

Make sure that Microsoft Office 2007 version or higher is already installed on your Windows system.

Before converting Excel to PDF, make sure that the default Microsoft virtual printerk is already set on your Windows system.

For Linux x86/x64, make sure that LibreOffice is already installed on your Linux system.

System requirements

Platform: Windows, Linux (x86 and x64)

Programming Language: C, C++, Python, Java, C#

License Key requirement: ‘Conversion’ module permission in the license key

SDK Version: Word and Excel (Foxit PDF SDK (C++, C#, Java) 7.3 or higher, Foxit PDF SDK (C) 7.4 or higher, Foxit PDF SDK (Python) 8.3 or higher), PowerPoint (Foxit PDF SDK (C, C++, C#, Java) 7.4 or higher, Foxit PDF SDK (Python) 8.3 or higher)

Example:

Note: For Linux x86/x64, the parameter engine_path” in the following sample codes represents the path of LibreOffice engine. To get the installed path of LibreOffice, you can input the command locate soffice.bin in a terminal, then the path will be shown, for example, “/usr/lib/libreoffice/program/soffice.bin”. Then the value of “engine_path” parameter is set to “/usr/lib/libreoffice/program”.

How to convert Word to PDF

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

# replace with the python2 lib path

site.addsitedir(‘../../../’)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Make sure that SDK has already been initialized successfully.

word_file_path = test.doc

output_path = saved.pdf

# Use default Word2PDFSettingData values.

word_convert_setting_data = Word2PDFSettingData()

if sys.platform == “linux”:

Convert.FromWord(word_file_path, “”, output_path, engine_path, word_convert_setting_data)

else:

Convert.FromWord(word_file_path, “”, output_path, word_convert_setting_data)

How to convert Excel to PDF

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

# replace with the python2 lib path

site.addsitedir(‘../../../’)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Make sure that SDK has already been initialized successfully.

excel_file_path = test.xls

output_path = saved.pdf

# Use default Excel2PDFSettingData values.

excel_convert_setting_data = Excel2PDFSettingData()

if sys.platform == “linux”:

Convert.FromExcel(excel_file_path, “”, output_path, engine_path, excel_convert_setting_data)

else:

Convert.FromExcel(excel_file_path, “”, output_path, excel_convert_setting_data)

How to convert PowerPoint to PDF

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

# replace with the python2 lib path

site.addsitedir(‘../../../’)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Make sure that SDK has already been initialized successfully.

ppt_file_path = test.ppt

output_path = saved.pdf

# Use default PowerPoint2PDFSettingData values.

ppt_convert_setting_data = PowerPoint2PDFSettingData()

if sys.platform == “linux”:

Convert.FromPowerPoint(ppt_file_path, “”, output_path, engine_path, ppt_convert_setting_data)

else:

Convert.FromPowerPoint(ppt_file_path, “”, output_path, ppt_convert_setting_data)

Output Preview

From version 7.4, Foxit PDF SDK supports output preview feature which can preview color separations and test different color profiles.

System requirements

Platform: Windows, Linux (x86 and x64), Mac (x64)

Programming Language: C, C++, Java, C#, Python, Objective-C

License Key requirement: valid license key

SDK Version: Foxit PDF SDK (C, C++, Java, C#, Objective-C) 7.4 or higher; Foxit PDF SDK (Python) 8.3 or higher

How to run the output preview demo

Before running the output preview demo in the “\examples\simple_demo\output_preview” folder, you should first set the folder path of “\res\icc_profile” in the SDK package to the variable default_icc_folder_path. For example:

# “default_icc_folder_path” is the path of the folder which contains default icc profile files. Please refer to Developer Guide for more details.

default_icc_folder_path = E:/foxitpdfsdk_X_X_win/res/icc_profile

Then, run the demo following the steps as the other demos.

How to do output preview using Foxit PDF SDK

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

# replace with the python2 lib path

site.addsitedir(‘../../../’)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Make sure that SDK has already been initialized successfully.

# Set folder path which contains default icc profile files.

Library.SetDefaultICCProfilesPath(default_icc_folder_path)

# Load a PDF document; Get a PDF page and parse it.

# Prepare a Renderer object and the matrix for rendering.

output_preview = OutputPreview(pdf_doc)

simulation_icc_file_path = icc_profile.icc

output_preview.SetSimulationProfile(simulation_icc_file_path)

output_preview.SetShowType(OutputPreview.e_ShowAll)

process_plates = output_preview.GetPlates(OutputPreview.e_ColorantTypeProcess)

spot_plates = output_preview.GetPlates(OutputPreview.e_ColorantTypeSpot)

process_size = int(process_plates.GetSize())

# Set check status of process plate to be true, if there’s any process plate.

for i in range(0, process_size):

output_preview.SetCheckStatus(process_plates[i], True)

spot_size = int(spot_plates.GetSize())

# Set check status of spot plate to be true, if there’s any spot plate.

for i in range(0, spot_size):

output_preview.SetCheckStatus(spot_plates[i], True)

# Generate preview bitmap

preview_bitmap = output_preview.GeneratePreviewBitmap(pdf_page, display_matrix, renderer)

Combination

Combination feature is used to combine several PDF files into one PDF file.

How to combine several PDF files into one PDF file

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

# replace with the python2 lib path

site.addsitedir(‘../../../’)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Make sure that SDK has already been initialized successfully.

info_array = CombineDocumentInfoArray()

info_array.Add(CombineDocumentInfo(input_path + AboutFoxit.pdf“, “”))

info_array.Add(CombineDocumentInfo(input_path + Annot_all.pdf“, “”))

info_array.Add(CombineDocumentInfo(input_path + SamplePDF.pdf“, “”))

savepath = output_directory + Test_Combined.pdf

option = Combination.e_CombineDocsOptionBookmark | Combination.e_CombineDocsOptionAcroformRename | \

Combination.e_CombineDocsOptionStructrueTree | Combination.e_CombineDocsOptionOutputIntents | \

Combination.e_CombineDocsOptionOCProperties | Combination.e_CombineDocsOptionMarkInfos | \

Combination.e_CombineDocsOptionPageLabels | Combination.e_CombineDocsOptionNames | \

Combination.e_CombineDocsOptionObjectStream | Combination.e_CombineDocsOptionDuplicateStream

progress = Combination.StartCombineDocuments(savepath, info_array, option)

progress_state = Progressive.e_ToBeContinued

while Progressive.e_ToBeContinued == progress_state:

progress_state = progress.Continue()

PDF Portfolio

PDF portfolios are a combination of files with different formats. Portfolio file itself is a PDF document, and files with different formats can be embedded into this kind of PDF document.

System requirements

Platform: Windows, Linux, Mac

Programming Language: C, C++, Java, C#, Python, Objective-C

License Key requirement: valid license key

SDK Version: Foxit PDF SDK (C, C++, Java, C#, Objective-C) 7.6 or higher; Foxit PDF SDK (Python) 8.3 or higher

Example:

How to create a new and blank PDF portfolio

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

# replace with the python2 lib path

site.addsitedir(‘../../../’)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Make sure that SDK has already been initialized successfully.

new_portfolio = Portfolio.CreatePortfolio()

# Set properties, add file/folder node to the new portfolio.

# Get portfolio PDF document object.

portfolio_pdf_doc = new_portfolio.GetPortfolioPDFDoc()

How to create a Portfolio object from a PDF portfolio

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

# replace with the python2 lib path

site.addsitedir(‘../../../’)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Make sure that SDK has already been initialized successfully.

portfolio_pdf_doc = PDFDoc(“portfolio.pdf“)

error_code = portfolio_pdf_doc.Load(“”)

if e_ErrSuccess == error_code:

if portfolio_pdf_doc.IsPortfolio():

existed_portfolio = Portfolio.CreatePortfolio(portfolio_pdf_doc)

How to get portfolio nodes

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

# replace with the python2 lib path

site.addsitedir(‘../../../’)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Make sure that SDK has already been initialized successfully.

# Portfolio object has been created, assume it is named “portfolio”.

root_node = portfolio.GetRootNode()

root_folder = PortfolioFolderNode (root_node)

sub_nodes = root_folder.GetSortedSubNodes()

sub_size = sub_nodes.GetSize()

for index in range(0, sub_size):

node = sub_nodes[index]

note_type = node.GetNodeType()

if note_type == PortfolioNode.e_TypeFolder:

folder_node = PortfolioFolderNode(node)

# Use PortfolioFolderNode’s getting method to get some properties.

sub_nodes_2 = folder_node.GetSortedSubNodes()

elif note_type == PortfolioNode.e_TypeFile:

file_node = PortfolioFileNode (node)

# Get file specification object from this file node, and then get/set information from/to this file specification object.

file_spec = file_node.GetFileSpec()

How to add file node or folder node

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

# replace with the python2 lib path

site.addsitedir(‘../../../’)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Make sure that SDK has already been initialized successfully.

# Portfolio object has been created, and the root folder node has been retrieved, assume it is named “root_folder”.

# Add file from path.

path_to_a_file = directory/Sample.txt

new_file_node_1 = root_folder.AddFile(path_to_a_file)

# User can update properties of file specification for new_file_node_1 if necessary.

# Add file from MyStreamCallback which is inherited from StreamCallback and implemented by user.

my_stream_callback = MyStreamCallback()

new_file_node_2 = root_folder.AddFile(my_stream_callback, file_name“)

# Please get file specification of new_file_node_2 and update properties of the file specification by its setting methods.

# Add a loaded PDF file.

# Open and load a PDF file, assume it is named “test_pdf_doc”.

new_file_node_3 = root_folder.AddPDFDoc(test_pdf_doc, pdf_file_name“)

# User can update properties of file specification for new_file_node_3 if necessary.

# Add a sub folder in root_folder.

new_sub_foldernode = root_folder.AddSubFolder(“Sub Folder-1“)

# User can add file or folder node to new_sub_foldernode.

How to remove a node

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

# replace with the python2 lib path

site.addsitedir(‘../../../’)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

# Make sure that SDK has already been initialized successfully.

# Remove a child folder node from its parent folder node.

parent_folder_node.RemoveSubNode(child_folder_node)

# Remove a child file node from its parent folder node.

parent_folder_node.RemoveSubNode(child_file_node)

Table Maker

From version 8.4, Foxit PDF SDK supports to add table to PDF files.

System requirements

Platform: Windows, Mac, Linux

Programming Language: C, C++, Java, C#, Python, Objective-C

License Key requirement: ‘TableMaker’ module permission in the license key

SDK Version: Foxit PDF SDK 8.4 or higher

How to add table to a PDF document

Foxit PDF SDK provides an electronictable demo located in the “\examples\simple_demo\electronictable” folder to show you how to use Foxit PDF SDK to add table to PDF document.

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

site.addsitedir(‘../../../’)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

index = 0

cell_array = TableCellDataArray()

for row in range(0, 4):

col_array = TableCellDataColArray()

for col in range(0, 3):

style = GetTableTextStyle(index)

cell_text = GetTableCellText(index)

cell_data = TableCellData(style, cell_text, Image(), RectF())

col_array.Add(cell_data)

index = index + 1

cell_array.Add(col_array)

page_width = pdf_page.GetWidth()

page_height = pdf_page.GetHeight()

outside_border_left = TableBorderInfo()

outside_border_left.line_width = 1

outside_border_left.table_border_style = TableBorderInfo.e_TableBorderStyleSolid

outside_border_right = TableBorderInfo()

outside_border_right.line_width = 1

outside_border_right.table_border_style = TableBorderInfo.e_TableBorderStyleSolid

outside_border_top = TableBorderInfo()

outside_border_top.line_width = 1

outside_border_top.table_border_style = TableBorderInfo.e_TableBorderStyleSolid

outside_border_bottom = TableBorderInfo()

outside_border_bottom.line_width = 1

outside_border_bottom.table_border_style = TableBorderInfo.e_TableBorderStyleSolid

inside_border_row_info = TableBorderInfo()

inside_border_row_info.line_width = 1

inside_border_row_info.table_border_style = TableBorderInfo.e_TableBorderStyleSolid

inside_border_col_info = TableBorderInfo()

inside_border_col_info.line_width = 1

inside_border_col_info.table_border_style = TableBorderInfo.e_TableBorderStyleSolid

data = TableData(RectF(100, 550, page_width – 100, page_height – 100), 4, 3, outside_border_left, outside_border_right,

outside_border_top, outside_border_bottom, inside_border_row_info, inside_border_col_info, TableCellIndexArray(), FloatArray(), FloatArray())

TableGenerator.AddTableToPage(pdf_page, data, cell_array)

Accessibility

From version 8.4, Foxit PDF SDK supports to tag PDF files.

System requirements

Platform: Windows, Mac, Linux

Programming Language: C, C++, Java, C#, Python, Objective-C

License Key requirement: ‘Accessibility’ module permission in the license key

SDK Version: Foxit PDF SDK 8.4 or higher

How to tag a PDF document

Foxit PDF SDK provides a taggedpdf demo located in the “\examples\simple_demo\taggedpdf” folder to show you how to use Foxit PDF SDK to tag a PDF document.

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

site.addsitedir(‘../../../’)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

….

pdfDoc = PDFDoc(input_file)

pdfDoc.Load(“”)

taggedpdf = TaggedPDF(pdfDoc)

progressive = taggedpdf.StartTagDocument(None)

progressState = Progressive.e_ToBeContinued

while (Progressive.e_ToBeContinued == progressState):

progressState = progressive.Continue()

pdfDoc.SaveAs(output_file_path, PDFDoc.e_SaveFlagNoOriginal)

PDF to Office Conversion

From version 9.0, Foxit PDF SDK provides APIs to convert PDF files to MS office suite formats while maintaining the layout and format of your original documents on Windows platform.

System requirements

Platform: Windows

Programming Language: C, C++, Java, Python, C#

License Key requirement: ‘PDF2Office’ module permission in the license key

SDK Version: Foxit PDF SDK for Windows (C, C++, Java, Python, C#) 9.0

PDF to Office engine files

Please contact Foxit support team or sales team to get the PDF to Office engine files package.

After getting the package, extract it to a desired directory (for example, extract the package to a directory: “D:/foxitpdfconversionsdk_win/“). It contains the following folders:

lib: engine libraries

res: the metrics data files are used for PDF to office

in the “lib” folder:

fpdfconversionsdk_win32.dll is the engine library for win x86.
fpdfconversionsdk_win64.dll is the engine library for win x64.

How to run the pdf2office demo

Foxit PDF SDK for Windows provides a pdf2office demo located in the “\examples\simple_demo\pdf2office” folder to show you how to use Foxit PDF SDK to convert PDF files to MS office suite formats.

Configure the demo

For pdf2office demo, you can configure the demo in the “\examples\simple_demo\pdf2office\pdf2office.py” file.

Specify the pdf2office engine directory

In the “pdf2office.py” file, add the path of the engine file “pdf2office” as follows, which will be used to convert PDF files to office files.

# Please ensure the path is valid.
PDF2Office.Initialize("D:/foxitpdfconversionsdk_win/lib/fpdfconversionsdk_win32.dll")

Specify the pdf2office metrics data files

setting_data = PDF2OfficeSettingData()
# Please ensure the path is valid.
setting_data.metrics_data_folder_path = "D:/foxitpdfconversionsdk_win/res/metrics_data"

(Optional) Specify whether to enable machine learning-based recognition functionality

setting_data.enable_ml_recognition = False
Run the demo

Once you run the demo successfully, the console will print the following by default:

The output files are located in “\examples\simple_demo\output_files\pdf2office” folder.

How to work with PDF2office API

import os
import sys
import site
 
if sys.version_info.major == 2:
    _PYTHON2_ = True
else:
    _PYTHON2_ = False
 
if _PYTHON2_:
    site.addsitedir('../../../')
    from FoxitPDFSDKPython2 import *
else:
    from FoxitPDFSDKPython3 import *
 
class CustomConvertCallback(ConvertCallback):
 
    def __init__(self, *args):
        if _PYTHON2_:
            super(CustomConvertCallback, self).__init__(*args)
        else:
            super().__init__(*args)
    def __del__(self):
        self.__disown__()
 
    def Release(self, *args):
        pass
 
    def NeedToPause(self, *args):
        return True
 
    def ProgressNotify(self, *args):
        converted_count = args[0]
        total_count = args[1]
 
callback = CustomConvertCallback()
progressive = PDF2Office.StartConvertToWord(input_path + "word.pdf", "", output_directory + "pdf2word_result.docx", setting_data, callback)
if progressive.GetRateOfProgress() != 100:
    state = Progressive.e_ToBeContinued
    while (Progressive.e_ToBeContinued == state):
        state = progressive.Continue()
print("Convert PDF file to Word format file with path.")
 
progressive = PDF2Office.StartConvertToExcel(input_path + "excel.pdf", "", output_directory + "pdf2excel_result.xlsx", setting_data, callback)
if progressive.GetRateOfProgress() != 100:
    state = Progressive.e_ToBeContinued
    while (Progressive.e_ToBeContinued == state):
        state = progressive.Continue()
print("Convert PDF file to Excel format file with path.")
 
progressive = PDF2Office.StartConvertToPowerPoint(input_path + "powerpoint.pdf", "", output_directory + "pdf2powerpoint_result.pptx", setting_data, callback)
if progressive.GetRateOfProgress() != 100:
   state = Progressive.e_ToBeContinued
   while Progressive.e_ToBeContinued == state:
   state = progressive.Continue()
print("Convert PDF file to PowerPoint format file with path.")

FAQ

How do I get text objects in a specified position of a PDF and change the contents of the text objects?

To get text objects in a specified position of a PDF and change the contents of the text objects using Foxit PDF SDK, you can follow the steps below:

Open a PDF file.

Load PDF pages and get the page objects.

Use PDFPage.GetGraphicsObjectAtPoint to get the text object at a certain position. Note: use the page object to get rectangle to see the position of the text object.

Change the contents of the text objects and save the PDF document.

Following is the sample code:

import sys

import site

if sys.version_info.major == 2:

_PYTHON2_ = True

else:

_PYTHON2_ = False

if _PYTHON2_:

#replace with the python2 lib path

site.addsitedir(‘../../../‘)

from FoxitPDFSDKPython2 import *

else:

from FoxitPDFSDKPython3 import *

def ChangeTextObjectContent():

try:

input_file = input_path + AboutFoxit.pdf

doc = PDFDoc(input_file)

error_code = doc.Load(“”)

if error_code != e_ErrSuccess:

print(“The PDFDoc {} Error: {}.format(input_file, error_code))

return False

# Get original shading objects from the first PDF page.

original_page = doc.GetPage(0)

original_page.StartParse(PDFPage.e_ParsePageNormal, None, False)

pointf = PointF()

pointf.x = 92

pointf.y = 762

arr = original_page.GetGraphicsObjectsAtPoint(pointf, 10, GraphicsObject.e_TypeText)

arr_size = arr.GetSize()

for i in range(0, arr_size):

graphobj = arr.GetAt(i)

textobj = graphobj.GetTextObject()

textobj.SetText(“Foxit Test“)

original_page.GenerateContent()

output_directory = output_path + graphics_objects/

output_file = output_directory + After_revise.pdf

doc.SaveAs(output_file, PDFDoc.e_SaveFlagNormal)

except Exception as ex:

print(ex.GetMessage())

return False

return True

Can I change the DPI of an embedded TIFF image?

No, you cannot change it. The DPI of the images in PDF files is static, so if the images already exist, Foxit PDF SDK does not have functions to change its DPI.

The solution is that you can use third-party library to change the DPI of an image, and then add it to the PDF file.

Note: Foxit PDF SDK provides a function “Image.SetDPIs” which can set the DPI property of an image object. However, it only supports the images that are created by Foxit PDF SDK or created by function “Image.AddFrame”, and it does not support the image formats of JPX, GIF and TIF.

Why do I encounter “Fail to initialize the engine file or cannot load the engine file” for OCR module on Windows 7 when running the OCR simple demo, even if the engine file has been upgraded to the latest and the engine path in the demo has been configured correctly?

For Windows 7, you need to copy the dll files starting with api-ms-win* and the ucrtbase.dll in the engine directory to the system directory.

If you are using a 32-bit engine and running on a 32-bit system, you need to copy the api-ms-win*.dll files and ucrtbase.dll from the engine directory to “C:/Windows/System32”.

If you are using a 32-bit engine and running on a 64-bit system, you need to copy the api-ms-win*.dll files and ucrtbase.dll from the engine directory to “C:/Windows/SysWOW64”.

If you are using a 64-bit engine, you need to copy the api-ms-win*.dll files and ucrtbase.dll from the engine directory to “C:/Windows/System32”.

How to run the Office2PDF functionality in Windows services?

To run the Office2PDF functionality in Windows services, you need to configure the Office Component Services and permissions.

Take the Word component as an example.

Press Win+R, and then type Dcomcnfg to open Component Services, find [Component Services] -> [Computers] -> [DCOM Config] -> [Microsoft Word 97-2003 Document], right-click it and select Properties. Choose [Identity], and set it to “The interactive user“.

Note: if you can’t find [Microsoft Word 97-2003 Document] with Dcomcnfg command, you can try to use the “comexp.msc -32” command.

Set permissions. click [Security], set the [Launch and Activation Permissions] and [Access Permissions] to Customize. Click Edit, and add the current login account of the system and enable all permissions.

After finishing the above settings, the Word2PDF functionality can be run in the Windows services.


Appendix

Supported JavaScript List

Objects’ property or method

Object Properites/Method Names Minimum Supported SDK Version
annotation properties alignment V7.0
author V7.0
contents V7.0
creationDate V7.0
fillColor V7.0
hidden V7.0
modDate V7.0
name V7.0
opacity V7.0
page V7.0
readOnly V7.0
rect V7.0
richContents V7.1
rotate V7.0
strokeColor V7.0
textSize V7.0
type V7.0
AP V9.0
arrowBegin V9.0
arrowEnd V9.0
attachIcon V9.0
attachment V9.0
borderEffectIntensity V9.0
borderEffectStyle V9.0
callout V9.0
caretSymbol V9.0
dash V9.0
delay V9.0
doc V9.0
doCaption V9.0
gestures V9.0
inReplyTo V9.0
intent V9.0
leaderExtend V9.0
leaderLength V9.0
lineEnding V9.0
lock V9.0
noteIcon V9.0
noView V9.0
point V9.0
points V9.0
popupOpen V9.0
popupRect V9.0
print V9.0
quads V9.0
refType V9.0
richDefaults V9.0
seqNum V9.0
soundIcon V9.0
style V9.0
subject V9.0
textFont V9.0
toggleNoView V9.0
vertices V9.0
width V9.0
annotation method destroy V7.0
getProps V9.0
setProps V9.0
getStateInModel V9.0
app properties activeDocs V4.0
calculate V4.0
formsVersion V4.0
fs V4.0
fullscreen V4.0
language V4.2
platform V4.0
runtimeHighlight V4.0
viewerType V4.0
viewerVariation V4.0
viewerVersion V4.0
printerNames V8.4
runtimeHighlightColor V8.4
constants V8.4
app methods alert V4.0
beep V4.0
browseForDoc V4.0
clearInterval V4.0
clearTimeOut V4.0
launchURL V4.0
mailMsg V4.0
response V4.0
setInterval V4.0
setTimeOut V4.0
popUpMenu V4.0
execDialog V8.4
execMenuItem V8.4
newDoc V8.4
openDoc V8.4
popUpMenuEx V8.4
addMenuItem V8.4
addSubMenu V8.4
addToolButton V8.4
removeToolButton V8.4
listMenuItems V8.4
trustedFunction V8.4
beginPriv V8.4
endPriv V8.4
color properties black V4.0
blue V4.0
cyan V4.0
dkGray V4.0
gray V4.0
green V4.0
ltGray V4.0
magenta V4.0
red V4.0
transparent V4.0
white V4.0
yellow V4.0
color methods convert V4.0
equal V4.0
document properties author V4.0
baseURL V4.0
bookmarkRoot V7.0
calculate V4.0
Collab V4.0
creationDate V4.0
creator V4.0
delay V4.0
dirty V4.0
documentFileName V4.0
external V4.0
filesize V4.0
icons V4.0
info V4.0
keywords V4.0
modDate V4.0
numFields V4.0
numPages V4.0
pageNum V4.0
path V4.0
producer V4.0
subject V4.0
title V4.0
URL V8.4
dataObjects V8.4
hostContainer V8.4
templates V8.4
media V8.4
dynamicXFAForm V8.4
mouseX V8.4
mouseY V8.4
pageWindowRect V8.4
securityHandler V8.4
zoom V8.4
zoomType V8.4
layout V8.4
xfa V8.4
document methods addAnnot V7.0
addField V4.0
addIcon V4.0
calculateNow V4.0
deletePages V4.0
exportAsFDF V4.0
flattenPages V7.1
getAnnot V7.0
getAnnots V7.0
getField V4.0
getIcon V4.0
getNthFieldName V4.0
getOCGs V4.0
getPageBox V4.0
getPageNthWord V4.0
getPageNthWordQuads V4.0
getPageNumWords V4.0
getPageRotation V7.0
getPrintParams V4.0
getURL V4.0
importAnFDF V4.0
insertPages V6.2
mailForm V4.0
print V4.0
removeField V4.0
replacePages V6.2
resetForm V4.0
submitForm V4.0
mailDoc V4.0
addWatermarkFromFile V8.4
addWatermarkFromText V8.4
getPageLabel V8.4
setPageLabels V8.4
gotoNamedDest V8.4
saveAs V8.4
scroll V8.4
setPageTabOrder V8.4
selectPageNthWord V8.4
syncAnnotScan V8.4
getAnnot3D V8.4
getAnnots3D V8.4
addLink V8.4
removeLinks V8.4
getLinks V8.4
importIcon V8.4
removeIcon V8.4
addWeblinks V8.4
removeWeblinks V8.4
closeDoc V8.4
exportDataObject V8.4
importDataObject V8.4
removeDataObject V8.4
getDataObject V8.4
embedDocAsDataObject V8.4
createTemplate V8.4
removeTemplate V8.4
getTemplate V8.4
exportAsText V8.4
importTextData V8.4
exportAsXFDF V8.4
importAnXFDF V8.4
exportAsXFDFStr V8.4
extractPages V8.4
movePage V8.4
newPage V8.4
getOCGOrder V8.4
setOCGOrder V8.4
setPageBoxes V8.4
setPageRotations V8.4
event properties change V4.0
changeEx V4.0
commitKey V4.0
fieldFull V4.0
keyDown V4.0
modifier V4.0
name V4.0
rc V4.0
selEnd V4.0
selStart V4.0
shift V4.0
source V4.0
target V4.0
targetName V4.0
type V4.0
value V4.0
willCommit V4.0
event methods add V9.0
field properties alignment V4.0
borderStyle V4.0
buttonAlignX V4.0
buttonAlignY V4.0
buttonFitBounds V4.0
buttonPosition V4.0
buttonScaleHow V4.0
buttonScaleWhen V4.0
calcOrderIndex V4.0
charLimit V4.0
comb V4.0
commitOnSelChange V4.0
currentValueIndices V4.0
defaultValue V4.0
doNotScroll V4.0
doNotSpellCheck V4.0
delay V4.0
display V4.0
doc V4.0
editable V4.0
exportValues V4.0
hidden V4.0
fileSelect V4.0
fillColor V4.0
lineWidth V4.0
highlight V4.0
multiline V4.0
multipleSelection V4.0
name V4.0
numItems V4.0
page V4.0
password V4.0
print V4.0
radiosInUnison V4.0
readonly V4.0
rect V4.0
required V4.0
richText V4.0
rotation V4.0
strokeColor V4.0
style V4.0
textColor V4.0
textFont V4.0
textSize V4.0
type V4.0
userName V4.0
value V4.0
valueAsString V4.0
richValue V9.0
submitName V9.0
field methods browseForFileToSubmit V4.0
buttonGetCaption V4.0
buttonGetIcon V4.0
buttonSetCaption V4.0
buttonSetIcon V4.0
checkThisBox V4.0
clearItems V4.0
defaultIsChecked V4.0
deleteItemAt V4.0
getArray V4.0
getItemAt V4.0
insertItemAt V4.0
isBoxChecked V4.0
isDefaultChecked V4.0
setAction V4.0
setFocus V4.0
setItems V4.0
buttonImportIcon V9.0
getLock V9.0
setLock V9.0
signatureGetModifications V9.0
signatureGetSeedValue V9.0
signatureInfo V9.0
signatureSetSeedValue V9.0
signatureSign V9.0
signatureValidate V9.0
global methods setPersistent V4.0
Icon properties name V4.0
util methods printd V4.0
printf V4.0
printx V4.0
scand V4.0
iconStreamFromIcon V9.0
identity properties loginName V4.2
name V4.2
corporation V4.2
email V4.2
collab properties user V6.2
ocg properties name V6.2
ocg methods setAction V6.2
bookmark properties color V8.4
open V8.4
name V8.4
parent V8.4
children V8.4
language V8.4
style V8.4
platform V8.4
bookmark methods createChild V8.4
insertChild V8.4
execute V8.4
setAction V8.4
remove V8.4
certificate properties binary V8.4
issuerDN V8.4
keyUsage V8.4
MD5Hash V8.4
privateKeyValidityEnd V8.4
privateKeyValidityStart V8.4
SHA1Hash V8.4
serialNumber V8.4
subjectCN V8.4
subjectDN V8.4
validityEnd V8.4
validityStart V8.4
RDN properties c V8.4
cn V8.4
e V8.4
l V8.4
o V8.4
ou V8.4
st V8.4
security properties handlers V9.0
security methods getHandler V9.0
importFromFile V9.0
securityHandler properties appearances V9.0
isLoggedIn V9.0
loginName V9.0
loginPath V9.0
name V9.0
uiName V9.0
securityHandler methods login V9.0
logout V9.0
newUser V9.0
signatureInfo properties objValidity V9.0
idValidity V9.0
idPrivValidity V9.0
docValidity V9.0
byteRange V9.0
verifyHandlerUIName V9.0
verifyHandlerName V9.0
verifyDate V9.0
subFilter V9.0
statusText V9.0
status V9.0
reason V9.0
name V9.0
mdp V9.0
location V9.0
handlerUIName V9.0
handlerUserName V9.0
handlerName V9.0
dateTrusted V9.0
date V9.0
search properties attachments V9.0
bookmarks V9.0
docText V9.0
ignoreAccents V9.0
markup V9.0
matchCase V9.0
matchWholeWord V9.0
maxDocs V9.0
proximity V9.0
stem V9.0
wordMatching V9.0
ignoreAsianCharacterWidth V9.0
search methods query V9.0
addIndex V9.0
removeIndex V9.0
link properties borderColor V8.4
borderWidth V8.4
highlightMode V8.4
rect V8.4
link methods setAction V8.4
app.media properties align V8.4
canResize V8.4
ifOffScreen V8.4
over V8.4
windowType V8.4
app.media methods createPlayer V8.4
openPlayer V8.4
doc.media methods getOpenPlayers V8.4
Playerargs properties doc V8.4
annot V8.4
rendition V8.4
URL V8.4
mimeType V8.4
settings V8.4
events V8.4
MediaPlayer properties isOpen V8.4
isPlaying V8.4
settings V8.4
visible V8.4
MediaPlayer methods close V8.4
play V8.4
seek V8.4
stop V8.4
MediaSettings properties autoPlay V8.4
baseURL V8.4
bgColor V8.4
bgOpacity V8.4
duration V8.4
floating V8.4
page V8.4
repeat V8.4
showUI V8.4
visible V8.4
volume V8.4
windowType V8.4
floating properties align V8.4
over V8.4
canResize V8.4
hasClose V8.4
hasTitle V8.4
title V8.4
ifOffScreen V8.4
rect V8.4
eventListener methods afterClose V9.0
afterPlay V9.0
afterReady V9.0
afterSeek V9.0
afterStop V9.0
onClose V9.0
onPlay V9.0
onReady V9.0
onSeek V9.0
onStop V9.0

Global methods

Method Names Minimum Supported SDK Version
AFNumber_Format V4.0
AFNumber_Keystroke V4.0
AFPercent_Format V4.0
AFPercent_Keystroke V4.0
AFDate_FormatEx V4.0
AFDate_KeystrokeEx V4.0
AFDate_Format V4.0
AFDate_Keystroke V4.0
AFTime_FormatEx V4.0
AFTime_KeystrokeEx V4.0
AFTime_Format V4.0
AFTime_Keystroke V4.0
AFSpecial_Format V4.0
AFSpecial_Keystroke V4.0
AFSpecial_KeystrokeEx V4.0
AFSimple V4.0
AFMakeNumber V4.0
AFSimple_Calculate V4.0
AFRange_Validate V4.0
AFMergeChange V4.0
AFParseDateEx V4.0
AFExtractNums V4.0


References

PDF reference 1.7

http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=51502

PDF reference 2.0

https://www.iso.org/standard/63534.html

Note: sdk_folder is the directory of unzipped package.


Support

Foxit Support

In order to provide you with a more personalized support for a resolution, please log in to your Foxit account and submit a ticket so that we can collect details about your issue. We will work to get your problem solved as quickly as we can once your ticket is routed to our support team.

You can also check out our Support Center, choose Foxit PDF SDK which also has a lot of helpful articles that may help with solving your issue.

Phone Support:

Phone: 1-866-MYFOXIT or 1-866-693-6948

Updated on March 21, 2024

Was this article helpful?
Thanks for your feedback. If you have a comment on how to improve the article, you can write it here: