public class

PDFNet

extends Object
java.lang.Object
   ↳ com.pdftron.pdf.PDFNet

Class Overview

PDFNet contains global library initialization, registration, configuration, and termination methods.

Note: There is only a single, static instance of PDFNet class. Initialization and termination methods need to be called only once per application session.

Summary

Constants
int e_CNS1 Character ordering: Chinese; Traditional
int e_GB1 Character ordering: Chinese; Simplified
int e_Identity Character ordering: Generic/Unicode
int e_Japan1 Character ordering: Japanese
int e_Japan2 Character ordering: Japanese
int e_Korea1 Character ordering: Korean
int e_icm Use Windows ICM2 (available only on Windows platforms).
int e_lcms Use LittleCMS (available on all supported platforms).
int e_no_cms No ICC color management.
Public Constructors
PDFNet()
Public Methods
static boolean IsARM()
Check if the platform is older ARM compatible.
static boolean IsARMv7()
Check if the platform is ARM v7 compatible.
static boolean addFontSubst(int ordering, String fontpath)
This method is deprecated. Use addResourceSearchPath(String) instead. Adds the font substitute
static boolean addFontSubst(String fontname, String fontpath)
This method is deprecated. Use addResourceSearchPath(String) instead. AddFontSubst functions can be used to create font substitutes that can override default PDFNet font selection algorithm.

These functions are useful in situations where referenced fonts are not present in the document and PDFNet font substitution algorithm is not producing desired results.

AddFontSubst(fontname, fontpath) maps the given font name (i.e. 'BaseFont' entry from the font dictionary) to a font file.

AddFontSubst(ordering, fontpath) maps the given character ordering (see Ordering entry in CIDSystemInfo dictionary; Section 5.6.2 in PDF Reference) to a font file. This method is less specific that the former variant of AddFontSubst, and can be used to override a range of missing fonts (or any missing font) with a predefined substitute.

The following is an example of using these functions to provide user defined font substitutes:

 PDFNet.initialize();
 PDFNet.setResourcesPath("c:/myapp/resources");
 // Specify specific font mappings...
 PDFNet.addFontSubst("MinionPro-Regular", "c:/myfonts/MinionPro-Regular.otf");
 PDFNet.addFontSubst("Times-Roman", "c:/windows/fonts/times.ttf");
 PDFNet.addFontSubst("Times-Italic", "c:/windows/fonts/timesi.ttf");

 // Specify more general font mappings...
 // Arial Unicode MS
 PDFNet.addFontSubst(PDFNet.e_Identity, "c:/myfonts/arialuni.ttf");
 PDFNet.addFontSubst(PDFNet.e_Japan1, "c:/myfonts/KozMinProVI-Regular.otf");
 PDFNet.addFontSubst(PDFNet.e_Japan2, "c:/myfonts/KozMinProVI-Regular.otf");
 PDFNet.addFontSubst(PDFNet.e_Korea1, "c:/myfonts/AdobeSongStd-Light.otf");
 PDFNet.addFontSubst(PDFNet.e_CNS1, "c:/myfonts/AdobeMingStd-Light.otf");
 PDFNet.addFontSubst(PDFNet.e_GB1, "c:/myfonts/AdobeMyungjoStd-Medium.otf");
 //...
 PDFDoc doc = new PDFDoc("c:/my.pdf");
 //...
 
 
static void addResourceSearchPath(String path)
Set the location of PDFNet resources file.
static void enableJavaScript(boolean enable)
A switch that can be used to turn on/off JavaScript engine
static String getResourcesPath()
Get the resources path.
static String getSystemFontList()
Get available fonts on the system.
static double getVersion()
Get the version.
static boolean hasBeenInitialized()
Returns true if PDFNet has been initialized.
static void initialize(Context context, int resId, String license_key)
Initializes PDFNet library.
static boolean isJavaScriptEnabled()
Test whether JavaScript is enabled
static void setColorManagement(int t)
Used to set a specific Color Management System (CMS) for use during color conversion operators, image rendering, etc.
static void setDefaultDeviceCMYKProfile(String icc_filename)
Set the default ICC color profile for DeviceCMYK color space.
static void setDefaultDeviceRGBProfile(String icc_filename)
Set the default ICC color profile for DeviceRGB color space.
static void setDefaultDiskCachingEnabled(boolean use_disk)
Sets the default policy on using temporary files.
static void setPersistentCachePath(String temp_path)
Set the location of persistent cache files.
static boolean setResourcesPath(String path)
Set the location of PDFNet resources file.
static void setTempPath(String temp_path)
Set the location of temporary folder.
static void setViewerCache(int max_cache_size, boolean on_disk)
Sets the default parameters of the cache used to render a PDFDoc instance.
static void terminate()
Terminates PDFNet library.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int e_CNS1

Character ordering: Chinese; Traditional

Constant Value: 4 (0x00000004)

public static final int e_GB1

Character ordering: Chinese; Simplified

Constant Value: 3 (0x00000003)

public static final int e_Identity

Character ordering: Generic/Unicode

Constant Value: 0 (0x00000000)

public static final int e_Japan1

Character ordering: Japanese

Constant Value: 1 (0x00000001)

public static final int e_Japan2

Character ordering: Japanese

Constant Value: 2 (0x00000002)

public static final int e_Korea1

Character ordering: Korean

Constant Value: 5 (0x00000005)

public static final int e_icm

Use Windows ICM2 (available only on Windows platforms).

Constant Value: 1 (0x00000001)

public static final int e_lcms

Use LittleCMS (available on all supported platforms).

Constant Value: 0 (0x00000000)

public static final int e_no_cms

No ICC color management.

Constant Value: 2 (0x00000002)

Public Constructors

public PDFNet ()

Public Methods

public static boolean IsARM ()

Check if the platform is older ARM compatible.

public static boolean IsARMv7 ()

Check if the platform is ARM v7 compatible.

public static boolean addFontSubst (int ordering, String fontpath)

This method is deprecated.
Use addResourceSearchPath(String) instead. Adds the font substitute

Parameters
ordering the ordering
fontpath path to font
Returns
  • true, if successful

public static boolean addFontSubst (String fontname, String fontpath)

This method is deprecated.
Use addResourceSearchPath(String) instead. AddFontSubst functions can be used to create font substitutes that can override default PDFNet font selection algorithm.

These functions are useful in situations where referenced fonts are not present in the document and PDFNet font substitution algorithm is not producing desired results.

AddFontSubst(fontname, fontpath) maps the given font name (i.e. 'BaseFont' entry from the font dictionary) to a font file.

AddFontSubst(ordering, fontpath) maps the given character ordering (see Ordering entry in CIDSystemInfo dictionary; Section 5.6.2 in PDF Reference) to a font file. This method is less specific that the former variant of AddFontSubst, and can be used to override a range of missing fonts (or any missing font) with a predefined substitute.

The following is an example of using these functions to provide user defined font substitutes:

 PDFNet.initialize();
 PDFNet.setResourcesPath("c:/myapp/resources");
 // Specify specific font mappings...
 PDFNet.addFontSubst("MinionPro-Regular", "c:/myfonts/MinionPro-Regular.otf");
 PDFNet.addFontSubst("Times-Roman", "c:/windows/fonts/times.ttf");
 PDFNet.addFontSubst("Times-Italic", "c:/windows/fonts/timesi.ttf");

 // Specify more general font mappings...
 // Arial Unicode MS
 PDFNet.addFontSubst(PDFNet.e_Identity, "c:/myfonts/arialuni.ttf");
 PDFNet.addFontSubst(PDFNet.e_Japan1, "c:/myfonts/KozMinProVI-Regular.otf");
 PDFNet.addFontSubst(PDFNet.e_Japan2, "c:/myfonts/KozMinProVI-Regular.otf");
 PDFNet.addFontSubst(PDFNet.e_Korea1, "c:/myfonts/AdobeSongStd-Light.otf");
 PDFNet.addFontSubst(PDFNet.e_CNS1, "c:/myfonts/AdobeMingStd-Light.otf");
 PDFNet.addFontSubst(PDFNet.e_GB1, "c:/myfonts/AdobeMyungjoStd-Medium.otf");
 //...
 PDFDoc doc = new PDFDoc("c:/my.pdf");
 //...
 
 

Parameters
fontname the fontname
fontpath path to font
Returns
  • true, if successful

public static void addResourceSearchPath (String path)

Set the location of PDFNet resources file.

Note: Add a path that will be searched when PDFNet requires additional resources such as fonts. Will not remove any existing search paths (so that multiple paths may be specified)

Parameters
path The new path to add to the resource search paths.

public static void enableJavaScript (boolean enable)

A switch that can be used to turn on/off JavaScript engine

Parameters
enable true to enable JavaScript engine, false to disable.

public static String getResourcesPath ()

Get the resources path.

Returns
  • the location of PDFNet resources folder. Empty string means that resources are located in your application folder.

public static String getSystemFontList ()

Get available fonts on the system.

Returns
  • A JSON list of fonts accessible to PDFNet

public static double getVersion ()

Get the version.

Returns
  • PDFNet version number.

public static boolean hasBeenInitialized ()

Returns true if PDFNet has been initialized.

public static void initialize (Context context, int resId, String license_key)

Initializes PDFNet library. Initialize() is usually called once, during process initialization.

Note: It is unsafe to call any other PDFNet API without first initializing the library.

Parameters
context The Context the activity is running in, through which it can access the current theme, resources, etc. It can be either an Application or an Activity context.
resId The resource ID for the PDFNet resources file (pdfnet.res). If this parameter is used, PDFNet will use the provided resource file. If not, some PDF documents may not render correctly. Note that the resource file name should be "pdfnet.res" when placing it under res/raw folder. Also, if it is desirable to store the resources file outside the package, it is possible to use setResourcesPath(String) in order to set the path to where the resources file is located.
license_key Optional license key used to activate the product. If the license_key is not specified, the product will work in demo mode. If the license_key is invalid, the function will throw an exception.
Throws
PDFNetException It can throw exception in the following cases:
  • invalid license key;
  • when a null context object is passed;
  • when there is no space to copy the resource file to the internal storage, resource ID does not exist, resource file does not exist or an error occurs when copying the file.

public static boolean isJavaScriptEnabled ()

Test whether JavaScript is enabled

Returns
  • true if it is enabled, false otherwise

public static void setColorManagement (int t)

Used to set a specific Color Management System (CMS) for use during color conversion operators, image rendering, etc.

Parameters
t identifies the type of color management to use.

public static void setDefaultDeviceCMYKProfile (String icc_filename)

Set the default ICC color profile for DeviceCMYK color space.

Note: You can use this method to override default PDFNet settings. For more information on default color spaces please refer to section 'Default Color Spaces' in Chapter 4.5.4 of PDF Reference Manual.

Parameters
icc_filename the new default device CMYK profile

public static void setDefaultDeviceRGBProfile (String icc_filename)

Set the default ICC color profile for DeviceRGB color space.

Note: You can use this method to override default PDFNet settings. For more information on default color spaces please refer to section 'Default Color Spaces' in Chapter 4.5.4 of PDF Reference Manual.

Parameters
icc_filename the new default device RGB profile

public static void setDefaultDiskCachingEnabled (boolean use_disk)

Sets the default policy on using temporary files.

Parameters
use_disk if parameter is true then new documents are allowed to create temporary files; otherwise all document contents will be stored in memory.

public static void setPersistentCachePath (String temp_path)

Set the location of persistent cache files. By default, it is set to context.getFilesDir().getPath().

This method is provided for applications that require tight control of the location where temporary files are created.

Parameters
temp_path path to persistent cache folder

public static boolean setResourcesPath (String path)

Set the location of PDFNet resources file.

Note: Starting with version 6.0.0 the resources (Fonts, CMaps, and standard PDF resources) were separated from the libraries on the PDFNet Android SDK. As a result, it is necessary to either initialize PDFNet passing the resource ID or set the path to the resources file using this method. Failing to set the resources file might result in wrong rendering of certain documents. The function can be also used to specify a default search path for ICC profiles, fonts, and other user defined resources.

Parameters
path The default resource directory path.
Returns
  • true if path is found, false otherwise.

public static void setTempPath (String temp_path)

Set the location of temporary folder. By default, it is set to context.getCacheDir().getPath(). Files saved to this location can be deleted by the OS when the disk space is low.

This method is provided for applications that require tight control of the location where temporary files are created.

Parameters
temp_path path to temporary folder

public static void setViewerCache (int max_cache_size, boolean on_disk)

Sets the default parameters of the cache used to render a PDFDoc instance. Any subsequently created documents will use these parameters. Caching is especially useful for interactive rendering, say in com.pdftron.pdf.PDFViewCtrl.

Note: Setting max_cache_size to zero will disable the cache.

Parameters
max_cache_size The maximum size, in bytes, of the entire document's page cache. Set to zero to disable the viewer cache. The maximum cache size is 100 MB.
on_disk If set to true, cache will be stored on the local filesystem. If set to 'false', cache will be stored in heap memory. The default value is false.

public static void terminate ()

Terminates PDFNet library. It is usually called once, when the process is terminated.

Note: It is unsafe to call any other PDFNet API after you terminate the library.