RNPdftron contains static methods for global library initialization, configuration, and utility methods.
Methods
-
initialize
-
Initializes PDFTron SDK with your PDFTron commercial license key. You can run PDFTron in demo mode by passing an empty string.
Parameters:
Name Type Description licenseKeystringyour PDFTron license key
Example
RNPdftron.initialize('your_license_key'); -
enableJavaScript
-
Enables JavaScript engine for PDFTron SDK, by default it is enabled.
Parameters:
Name Type Description enabledbooleanwhether to enable or disable JavaScript engine
Example
RNPdftron.enableJavaScript(true);
-
getVersion
-
Gets the current PDFNet version.
Returns:
Name Type Description versionPromise<string>current PDFNet version Example
RNPdftron.getVersion().then((version) => { console.log("Current PDFNet version:", version); }); -
getPlatformVersion
-
Gets the version of current platform (Android/iOS).
Returns:
Name Type Description platformVersionPromise<string>current platform version (Android/iOS) Example
RNPdftron.getPlatformVersion().then((platformVersion) => { console.log("App currently running on:", platformVersion); }); -
getSystemFontList
-
Gets the font list available on the OS (Android only). This is typically useful when you are mostly working with non-ascii characters in the viewer.
Returns:
Name Type Description fontListPromise<string>the font list available on Android Example
RNPdftron.getSystemFontList().then((fontList) => { console.log("OS font list:", fontList); }); -
clearRubberStampCache
-
Clear the information and bitmap cache for rubber stamps (Android only). This is typically useful when the content of rubber stamps has been changed in the viewer.
Returns:
Type Promise<void>Example
RNPdftron.clearRubberStampCache().then(() => { console.log("Rubber stamp cache cleared"); }); -
encryptDocument
-
Encrypts (password-protect) a document (must be a PDF).
Note: This function does not lock the document, it cannot be used while the document is opened in the viewer.
Parameters:
Name Type Description filePathstringthe local file path to the file
passwordstringthe password you would like to set
currentPasswordstringthe current password, use empty string if no password
Returns:
Type Promise<void>Example
RNPdftron.encryptDocument("/sdcard/Download/new.pdf", "1111", "").then(() => { console.log("done password"); }); -
pdfFromOfficeTemplate
-
Generates a PDF using a template in the form of an Office document and replacement data in the form of a JSON object. For more information please see our template guide.
The user is responsible for cleaning up the temporary file that is generated.
Parameters:
Name Type Description docxPathstringthe local file path to the template file
jsonobjectthe replacement data in the form of a JSON object
Returns:
Name Type Description resultPdfPathPromise<string>the local file path to the generated PDF Example
RNPdftron.pdfFromOfficeTemplate("/sdcard/Download/red.docx", json).then((resultPdfPath) => { console.log(resultPdfPath); }); -
exportAsImage
-
Export a PDF page to an image format defined in Config.ExportFormat.
Unlike DocumentView.exportAsImage, this method is static and should only be called before a
DocumentViewinstance has been created or else unexpected behaviour can occur. This method also takes a local file path to the desired PDF.Parameters:
Name Type Description pageNumberintthe page to be converted; if the value does not refer to a valid page number, the file path will be undefined
dpidoublethe output image resolution
exportFormatConfig.ExportFormatimage format to be exported to
filePathstringlocal file path to pdf
Returns:
Name Type Description resultImagePathPromise<string>the temp path of the created image, user is responsible for clean up the cache Example
RNPdftron.exportAsImage(1, 92, Config.ExportFormat.BMP, "/sdcard/Download/red.pdf").then( (resultImagePath) => { console.log('export', resultImagePath); });