RNPdftron

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
licenseKey string

your 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
enabled boolean

whether to enable or disable JavaScript engine

Example
RNPdftron.enableJavaScript(true);

getVersion

Gets the current PDFNet version.

Returns:
Name Type Description
version Promise<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
platformVersion Promise<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
fontList Promise<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
filePath string

the local file path to the file

password string

the password you would like to set

currentPassword string

the 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
docxPath string

the local file path to the template file

json object

the replacement data in the form of a JSON object

Returns:
Name Type Description
resultPdfPath Promise<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 DocumentView instance 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
pageNumber int

the page to be converted; if the value does not refer to a valid page number, the file path will be undefined

dpi double

the output image resolution

exportFormat Config.ExportFormat

image format to be exported to

filePath string

local file path to pdf

Returns:
Name Type Description
resultImagePath Promise<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);
});