ComPDFKit
ComPDFKit contains static methods for global library initialization, configuration, and utility methods.
Initialize SDK
Method Name: initWithPath(licensePath: string)
Use your ComPDFKit commercial license key XML file to initialize the ComPDFKit SDK. Please contact our sales team to obtain a trial license.
Parameters:
| Name | Type | Description |
|---|---|---|
| licensePath | string | Path to the license XML file |
Returns a Promise.
| Name | Type | Description |
|---|---|---|
| result | boolean | Returns true if initialization is successful, otherwise false. |
// Android: Place in the assets directory
await ComPDFKit.initWithPath('assets://license_key_android.xml')
// iOS: Copy to the iOS project root directory
await ComPDFKit.initWithPath('license_key_ios.xml')
// Alternatively, use an absolute file path
await ComPDFKit.initWithPath('/data/data/your.package.name/files/license_key.xml')init_
Initialize the ComPDFKit SDK offline using your ComPDFKit commercial license key. Please contact our sales to obtain a trial license.
Parameters:
| Name | Type | Description |
|---|---|---|
| license | String | Your ComPDFKit license key |
Returns a Promise.
| Name | Type | Description |
|---|---|---|
| result | boolean | Returns true if initialization is successful, otherwise returns false. |
ComPDFKit.init_('your compdfkit license')initialize
Use your ComPDFKit commercial license key to initialize the ComPDFKit SDK using online authentication. Please contact our sales to obtain a trial license.
Parameters:
| Name | Type | Description |
|---|---|---|
| androidOnlineLicense | string | Your ComPDFKit for React Native Android online license key. |
| iosOnlineLicense | string | Your ComPDFKit for React Native iOS online license key. |
Returns a Promise.
| Name | Type | Description |
|---|---|---|
| result | boolean | Returns true if initialization is successful, otherwise returns false. |
ComPDFKit.initialize('android online license', 'ios online license')getVersionCode
Get the version number of the ComPDFKit SDK.
For example: '2.0.1'
Returns a Promise.
| Name | Type | Description |
|---|---|---|
| versionCode | String | the version number of the ComPDFKit SDK. |
ComPDFKit.getVersionCode().then((versionCode : string) => {
console.log('ComPDFKit SDK Version:', versionCode)
})getSDKBuildTag
Get the build tag of the ComPDFKit PDF SDK.
For example: "build_beta_2.0.0_42db96987_202404081007"
Returns a Promise.
| Name | Type | Description |
|---|---|---|
| buildTag | String | the build tag of the ComPDFKit PDF SDK. |
ComPDFKit.getSDKBuildTag().then((buildTag : string) => {
console.log('ComPDFKit Build Tag:', buildTag)
})openDocument
Used to present a PDF document.
Parameters:
| Name | Type | Description |
|---|---|---|
| document | string | The path to the PDF document to be presented. |
| password | string | PDF document password. |
| configuration | string | Configuration objects to customize the appearance and behavior of ComPDFKit. |
- (Android) For local storage file path:
document = '/storage/emulated/0/Download/PDF_document.pdf'
ComPDFKit.openDocument(document, '', ComPDFKit.getDefaultConfig({}))- (Android) For content Uri:
document = 'content://...'
ComPDFKit.openDocument(document, '', ComPDFKit.getDefaultConfig({}))- (Android) For assets path:
document = "file:///android_asset/..."
ComPDFKit.openDocument(document, '', ComPDFKit.getDefaultConfig({}))- (iOS) For app bundle file path:
document = 'pdf_document.pdf'
ComPDFKit.openDocument(document, '', ComPDFKit.getDefaultConfig({}))getDefaultConfig
When using the ComPDFKit.openDocument method or the CPDFReaderView UI component to display a PDF file, you need to pass configuration parameters to customize the UI features and PDF view properties. ComPDFKit provides default configuration parameters through ComPDFKit.getDefaultConfig. You can retrieve them using the following example:
ComPDFKit.getDefaultConfig({})You can modify certain parameters to meet your requirements. Here are some usage examples:
- Setting the initial display mode and available mode list. The following code is an example that enables only the viewer mode and annotation mode:
ComPDFKit.getDefaultConfig({
modeConfig: {
initialViewMode: CPDFViewMode.VIEWER,
availableViewModes: [
CPDFViewMode.VIEWER,
CPDFViewMode.ANNOTATIONS
]
}
})- Setting the enabled annotation types and the default annotation attribute values list. For example, enabling only note annotations and setting the color and transparency of note annotations:
ComPDFKit.getDefaultConfig({
annotationsConfig:{
availableType:[
CPDFAnnotationType.NOTE
],
availableTools:[
CPDFConfigTool.SETTING,
CPDFConfigTool.UNDO,
CPDFConfigTool.REDO
],
initAttribute:{
note:{
color: '#1460F3',
alpha: 255
}
}
}
})3.Setting the display mode and page turning direction:
ComPDFKit.getDefaultConfig({
readerViewConfig:{
displayMode: CPDFDisplayMode.DOUBLE_PAGE,
verticalMode: false
}
})For more configuration parameter descriptions, please see CPDFCONFIGURATION.md.
removeSignFileList
Delete the signature saved in the electronic signature annotation list.
Returns a Promise.
| Name | Type | Description |
|---|---|---|
| result | boolean | Returns true if the deletion was successful, otherwise returns false. |
ComPDFKit.removeSignFileList();pickFile
Opens the system file picker to select a PDF document.
Returns a Promise.
| Name | Type | Description |
|---|---|---|
| result | string |
String? path = ComPDFKit.pickFile();setImportFontDir
Imports font files to support displaying additional languages. mported fonts will appear in the font list for FreeText annotations and text editing.
Note: Fonts must be imported before initializing the SDK.
steps to import fonts:
- Copy the fonts you want to import into a custom folder.
- Call
setImportFontDirwith the folder path as a parameter. - Initialize the SDK using
ComPDFKit.init_.
Parameters:
| Name | Type | Description |
|---|---|---|
| fontDir | string | The path to the folder containing font files to import. |
| addSysFont | string | Whether to include system fonts in the font list. |
Returns a Promise.
| Name | Type | Description |
|---|---|---|
| result | bool |
// Set the font directory
ComPDFKit.setImportFontDir('fontdir', true);
// Initialize the ComPDFKit SDK
ComPDFKit.init_('your license key');createUri
This method is supported only on the Android platform. It is used to create a URI for saving a file on the Android device. The file is saved in the Downloads directory by default, but you can specify a subdirectory within Downloads using the [childDirectoryName] parameter. If the [childDirectoryName] is not provided, the file will be saved directly in the Downloads directory. The [fileName] parameter is required to specify the name of the file (e.g., test.pdf).
Parameters:
| Name | Type | Description |
|---|---|---|
| fileName | string | specifies the name of the file, for example test.pdf. |
| childDirectoryName | string | specifies a subdirectory within the Downloads folder. |
| mimeType | string | the MIME type of the file, defaulting to application/pdf. |
Returns a Promise.
| Name | Type | Description |
|---|---|---|
| uri | string | Returns the uri used to save the file |
const uri: string = await ComPDFKit.createUri('test.pdf', '', 'application/pdf');