PTPDFNet
@interface PTPDFNet : NSObject
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.-
Initializes PDFNet library. Initialize must be called once, before any other PDFNet method is used. You must provide a trial or purchased license key. Please see https://www.pdftron.com/key_init_ios for more information.
@exception If the license_key is missing or invalid, the function will throw an exception.
Declaration
Objective-C
+ (void)Initialize:(NSString *)license_key;
Swift
class func initialize(_ license_key: String!)
Parameters
license_key
The trial or purchased license key. Please see https://www.pdftron.com/key_init_ios for more information.
-
Undocumented
Declaration
Objective-C
+ (BOOL)IsInitialized;
Swift
class func isInitialized() -> Bool
-
Terminates PDFNet library. Terminate() is usually called once, when the process is terminated.
Note
it is unsafe to call any other PDFNet API after you terminate the library.
Declaration
Objective-C
+ (void)Terminate:(int)termination_level;
Swift
class func terminate(_ termination_level: Int32)
Parameters
termination_level
Optional termination level used to decide what operations need to be included
-
A switch that can be used to turn on/off JavaScript engine
Declaration
Objective-C
+ (void)EnableJavaScript:(BOOL)enable;
Swift
class func enableJavaScript(_ enable: Bool)
Parameters
enable
true to enable JavaScript engine, false to disable.
-
Test whether JavaScript is enabled
Declaration
Objective-C
+ (BOOL)IsJavaScriptEnabled;
Swift
class func isJavaScriptEnabled() -> Bool
Return Value
true if it is enabled, false otherwise
-
Sets the location of PDFNet resource file.
Note
Starting with v.4.5 PDFNet no longer requires a seperate resource file, and so this function is not required for proper PDFNet initialization. It remains available for backward compatibility. On mobile systems (iOS, Android, etc.) this method is required for proper initialization starting with version 6.0. (This helps reduce overall app size.) The function can be used on all platforms to specify a default search path for ICC profiles, fonts, and other user defined resources.
Declaration
Objective-C
+ (BOOL)SetResourcesPath:(NSString *)path;
Swift
class func setResourcesPath(_ path: String!) -> Bool
Parameters
path
- The default resource directory path.
Return Value
true if path is found, false otherwise.
-
Declaration
Objective-C
+ (NSString *)GetResourcesPath;
Swift
class func getResourcesPath() -> String!
Return Value
the location of PDFNet resources folder. Empty string means that resources are located in your application folder.
-
Sets the location of PDFNet resource file.
Note
Starting with v.4.5 PDFNet no longer requires a seperate resource file, and so this function is not required for proper PDFNet initialization. The function can be used on all platforms to specify search paths for ICC profiles, fonts, and other user defined resources.
Declaration
Objective-C
+ (void)AddResourceSearchPath:(NSString *)path;
Swift
class func addResourceSearchPath(_ path: String!)
Parameters
path
- The resource directory path to add to the search list.
-
Declaration
Objective-C
+ (double)GetVersion;
Swift
class func getVersion() -> Double
Return Value
PDFNet version number.
-
Sets 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.@exception the function will throw Exception if the ICC profile can’t be found or if it fails to open.
Declaration
Objective-C
+ (void)SetDefaultDeviceCMYKProfile:(NSString *)icc_filename;
Swift
class func setDefaultDeviceCMYKProfile(_ icc_filename: String!)
-
Sets 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.@exception the function will throw Exception if the ICC profile can’t be found or if it fails to open.
Declaration
Objective-C
+ (void)SetDefaultDeviceRGBProfile:(NSString *)icc_filename;
Swift
class func setDefaultDeviceRGBProfile(_ icc_filename: String!)
-
Sets the default policy on using temporary files.
@use_disk if parameter is true then new documents are allowed to create temporary files; otherwise all document contents will be stored in memory.
Declaration
Objective-C
+ (void)SetDefaultDiskCachingEnabled:(BOOL)use_disk;
Swift
class func setDefaultDiskCachingEnabled(_ use_disk: Bool)
-
Sets the default compression level for Flate (ZLib).
- parameter: level An integer in range 0-9 representing the compression value to use as
a default for any Flate streams (e.g used to compress content streams, PNG images, etc). The library normally uses the default compression level (Z_DEFAULT_COMPRESSION). For most images, compression values in the range 3-6 compress nearly as well as higher levels, and do so much faster. For on-line applications it may be desirable to have maximum speed Z_BEST_SPEED = 1). You can also specify no compression (Z_NO_COMPRESSION = 0).
@default Z_DEFAULT_COMPRESSION (-1).
Declaration
Objective-C
+ (void)SetDefaultFlateCompressionLevel:(int)level;
Swift
class func setDefaultFlateCompressionLevel(_ level: Int32)
-
Sets the default parameters for the viewer cache. Any subsequently created documents will use these parameters.
- parameter: max_cache_size - The maximum size, in bytes, of the entire document's page cache. Set to zero to disable the viewer cache. - parameter: 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. @default Desktop: max_cache_size = 512 MB, on_disk = true | Mobile: max_cache_size = 100 MB, on_disk = false
Declaration
Objective-C
+ (void)SetViewerCache:(unsigned long)max_cache_size on_disk:(BOOL)on_disk;
Swift
class func setViewerCache(_ max_cache_size: UInt, on_disk: Bool)
-
AddFontSubst functions can be used to create font substitutes that can override default PDFNet font selection algorithm.
AddFontSubst 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.
The following is an example of using this function 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"); ... PDFDoc doc("c:/my.pdf"); ...
Declaration
Objective-C
+ (BOOL)AddFontSubstWithFontName:(NSString *)fontname fontpath:(NSString *)fontpath;
Swift
class func addFontSubst(withFontName fontname: String!, fontpath: String!) -> Bool
-
AddFontSubst functions can be used to create font substitutes that can override default PDFNet font selection algorithm.
AddFontSubst 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(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 this function to provide user defined font substitutes:
PDFNet::Initialize(); PDFNet::SetResourcesPath("c:/myapp/resources"); // Specify more general font mappings... PDFNet::AddFontSubst(PDFNet::e_Identity, "c:/myfonts/arialuni.ttf"); // Arial Unicode MS 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("c:/my.pdf"); ...
Declaration
Objective-C
+ (BOOL)AddFontSubstWithOrdering:(PTCharacterOrdering)ordering fontpath:(NSString *)fontpath;
Swift
class func addFontSubst(with ordering: PTCharacterOrdering, fontpath: String!) -> Bool
-
Set the location of temporary folder.
This method is provided for applications that require tight control of the location where temporary files are created.
Declaration
Objective-C
+ (void)SetTempPath:(NSString *)temp_path;
Swift
class func setTempPath(_ temp_path: String!)
-
Set the location of persistent cache files.
This method is provided for applications that require tight control of the location where temporary files are created.
Declaration
Objective-C
+ (void)SetPersistentCachePath:(NSString *)persistent_path;
Swift
class func setPersistentCachePath(_ persistent_path: String!)
-
Undocumented
Declaration
Objective-C
+ (NSString *)GetSystemFontList;
Swift
class func getSystemFontList() -> String!
-
Undocumented
Declaration
Objective-C
+ (void)SetLogLevel: (PTLogLevel)level;
Swift
class func setLogLevel(_ level: PTLogLevel)
-
Add PDFTron Custom Security handler
Note
calling this function is a requirement to load files encrypted with PDFTronCustomSecurityHandler.Declaration
Objective-C
+ (void)AddPDFTronCustomHandler:(unsigned int)custom_id;
Swift
class func addPDFTronCustomHandler(_ custom_id: UInt32)
Parameters
custom_id
The user’s custom id. The id should match what was used to create PDFTronCustomSecurityHandler when encrypting the document.
-
Declaration
Objective-C
+ (NSString *)GetVersionString;
Swift
class func getVersionString() -> String!
Return Value
PDFNet version as a string.
-
Enable writing API usage locally.
Declaration
Objective-C
+ (void)SetWriteAPIUsageLocally:(BOOL)write_usage;
Swift
class func setWriteAPIUsageLocally(_ write_usage: Bool)
Parameters
write_usage
if parameter is true API usage will be written to local JSON files in the persistent cache path otherwise no API usage is saved.
-
Sets the connection error handling behaviour for Apryse SDK The default for this method is e_continue
Declaration
Objective-C
+ (void)SetConnectionErrorHandlingMode:(PTConnectionErrorHandlingMode)mode;
Swift
class func setConnectionErrorHandlingMode(_ mode: PTConnectionErrorHandlingMode)
Parameters
mode
Rules that Apryse SDK will follow after a connection error.
-
Sets the error handling function to be called when an error is encountered when connecting to PDFTron Web Services.
Declaration
Objective-C
+ (void)SetConnectionErrorProc:(PTCallback *)instance;
Swift
class func setConnectionErrorProc(_ instance: PTCallback!)
Parameters
error_proc
Connection error handling callback function (or delegate in .NET)
data
Custom data to be passed as the fourth parameter to ‘error_proc’.
-
Undocumented
Declaration
Objective-C
- (instancetype)init;
Swift
init!()
-
A convenience method to translate Obj-C exceptions into Swift errors. Usage example:
do { try PTPDFNet.catchException { doc = PTPDFDoc(filepath: docPath!) } } catch { print("Caught exception: \(error)") }
Declaration
Objective-C
+ (BOOL)CatchException:(void (^)(void))tryBlock error:(NSError **)error;
Swift
class func catchException(_ tryBlock: (() -> Void)!) throws