CPDFReaderView - Props
Open Document
CPDFReaderView
is a React component designed to display PDF documents. Below are details about the required document
prop.
document
Specifies the path or URI of the PDF document to be displayed.
- Type:
string
- Required: Yes
**Usage Examples:
- (Android) For local storage file path:
<CPDFReaderView
document={'/storage/emulated/0/Download/PDF_document.pdf'}/>
- (Android) For content Uri:
<CPDFReaderView
document={'content://...'}/>
- (Android) For assets path:
<CPDFReaderView
document={'file:///android_asset/...'}/>
- (iOS) For app bundle file path:
<CPDFReaderView
document={'pdf_document.pdf'}/>
password
The password to open the document is an optional parameter.
- Type:
string
Usage Examples:
<CPDFReaderView
document={'pdf_document.pdf'}
password={'password'}/>
configuration
Used to pass configuration parameters when rendering a PDF file to customize UI features and PDF view properties. ComPDFKit
provides default configuration parameters through ComPDFKit.getDefaultConfig
.
- Type:
string
- Required: Yes
Usage Examples:
<CPDFReaderView
document={samplePDF}
configuration={ComPDFKit.getDefaultConfig({
})}
style={{flex:1}}
/>
Document
hasChange
Checks whether the document has been modified.
Returns a Promise.
Promise Parameters:
Name | Type | Description |
---|---|---|
hasChange | boolean | true : The document has been modified, false : The document has not been modified. |
const hasChange = await pdfReaderRef.current?.hasChange();
save
Save the current document changes.
Returns a Promise.
Promise Parameters:
Name | Type | Description |
---|---|---|
result | boolean | true: Save successful, false: Save failed. |
const saveResult = await pdfReaderRef.current.save();
onSaveDocument
function, optional
This function will be called when the document is saved.
Parameters:
Name | Type | Description |
---|---|---|
pageNumber | int | the current page number |
<CPDFReaderView
onSaveDocument={()=>{}}
/>
Viewer
setMargins
Set the current PDF view margin.
Parameters:
Name | Type | Description |
---|---|---|
left | int | margin left |
top | int | margin top |
right | int | margin right |
bottom | int | margin bottom |
await pdfReaderRef.current?.setMargins(10,10,10,10);
Page
setDisplayPageIndex
Jump to the index page.
Parameters:
Name | Type | Description |
---|---|---|
pageIndex | int | Jump to page number |
await pdfReaderRef.current?.setDisplayPageIndex(1);
getCurrentPageIndex
get current page index.
Returns a Promise.
Promise Parameters:
Name | Type | Description |
---|---|---|
pageIndex | int | Returns the page index of the current document display |
const pageIndex = await pdfReaderRef.current?.getCurrentPageIndex();
onPageChanged
function, optional
This function is called when the page number has been changed.
Parameters:
Name | Type | Description |
---|---|---|
pageNumber | int | the current page number |
<CPDFReaderView
onPageChanged={(pageIndex:number)=>{
}}
/>
Annotations
import Annotations
Imports annotations from the specified XFDF file into the current PDF document.
Parameters:
Name | Type | Description |
---|---|---|
xfdfFile | string | Path of the XFDF file to be imported. The Android platform supports the following paths: - assets file:'file:///android_assets/test.xfdf' - file path: '/data/xxx.xfdf' - Uri: 'content://xxxx' |
Returns a Promise.
Promise Parameters:
Name | Type | Description |
---|---|---|
result | boolean | true: import successful, false: import failed. |
const result = await pdfReaderRef.current.importAnnotations('xxx.xfdf');
export Annotations
Exports annotations from the current PDF document to an XFDF file.
Returns a Promise.
Promise Parameters:
Name | Type | Description |
---|---|---|
xfdfPath | string | The path of the XFDF file if export is successful; an empty string if the export fails. |
const exportXfdfFilePath = await pdfReaderRef.current?.exportAnnotations();
removeAllAnnotations
Delete all comments in the current document.
Returns a Promise.
Promise Parameters:
Name | Type | Description |
---|---|---|
result | boolean | true、false |
const removeResult = await pdfReaderRef.current?.removeAllAnnotations();