Skip to content

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:
tsx
<CPDFReaderView
	document={'/storage/emulated/0/Download/PDF_document.pdf'}/>
  • (Android) For content Uri:
tsx
<CPDFReaderView
	document={'content://...'}/>
  • (Android) For assets path:
tsx
<CPDFReaderView
	document={'file:///android_asset/...'}/>
  • (iOS) For app bundle file path:
tsx
<CPDFReaderView	
	document={'pdf_document.pdf'}/>

password

The password to open the document is an optional parameter.

  • Type: string

Usage Examples:

tsx
<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:

tsx
<CPDFReaderView
  document={samplePDF}
  configuration={ComPDFKit.getDefaultConfig({

  })}
  style={{flex:1}}
  />

Document

hasChange

Checks whether the document has been modified.

Returns a Promise.

Promise Parameters:

NameTypeDescription
hasChangebooleantrue: The document has been modified,
false: The document has not been modified.
tsx
const hasChange = await pdfReaderRef.current?.hasChange();

save

Save the current document changes.

Returns a Promise.

Promise Parameters:

NameTypeDescription
resultbooleantrue: Save successful,
false: Save failed.
js
const saveResult = await pdfReaderRef.current.save();

onSaveDocument

function, optional

This function will be called when the document is saved.

Parameters:

NameTypeDescription
pageNumberintthe current page number
tsx
<CPDFReaderView
	onSaveDocument={()=>{}}
	/>

Viewer

setMargins

Set the current PDF view margin.

Parameters:

NameTypeDescription
leftintmargin left
topintmargin top
rightintmargin right
bottomintmargin bottom
tsx
await pdfReaderRef.current?.setMargins(10,10,10,10);

Page

setDisplayPageIndex

Jump to the index page.

Parameters:

NameTypeDescription
pageIndexintJump to page number
tsx
await pdfReaderRef.current?.setDisplayPageIndex(1);

getCurrentPageIndex

get current page index.

Returns a Promise.

Promise Parameters:

NameTypeDescription
pageIndexintReturns the page index of the current document display
tsx
const pageIndex = await pdfReaderRef.current?.getCurrentPageIndex();

onPageChanged

function, optional

This function is called when the page number has been changed.

Parameters:

NameTypeDescription
pageNumberintthe current page number
tsx
<CPDFReaderView
	onPageChanged={(pageIndex:number)=>{
	}}
  />

Annotations

import Annotations

Imports annotations from the specified XFDF file into the current PDF document.

Parameters:

NameTypeDescription
xfdfFilestringPath 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:

NameTypeDescription
resultbooleantrue: import successful,
false: import failed.
tsx
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:

NameTypeDescription
xfdfPathstringThe path of the XFDF file if export is successful; an empty string if the export fails.
tsx
const exportXfdfFilePath = await pdfReaderRef.current?.exportAnnotations();

removeAllAnnotations

Delete all comments in the current document.

Returns a Promise.

Promise Parameters:

NameTypeDescription
resultbooleantrue、false
tsx
const removeResult = await pdfReaderRef.current?.removeAllAnnotations();