Adds a plain reply to an annotation.
Mark and review state replies are managed by dedicated state APIs and are not created by this method.
The parent annotation to reply to.
Reply content and optional author/title.
The created plain reply annotation, or null if creation failed.
Gets all replies attached to an annotation.
Returned reply objects include their content, markState, and reviewState. Native mark/review state replies are implementation details and are not exposed through a public replyType field.
The parent annotation.
Replies attached to the annotation.
Updates a plain annotation reply.
The plain reply annotation to update.
Updated reply content and optional author/title.
true when the reply was updated.
Removes a plain annotation reply.
The plain reply annotation to remove.
true when the reply was removed.
Removes all plain replies attached to an annotation.
Mark and review state replies are preserved.
The parent annotation.
true when all plain replies were removed.
Removes an annotation from the current page.
The annotation to be removed.
Sets the mark state of an annotation or annotation reply.
The annotation or reply annotation to update.
The mark state.
true when the state was updated.
await pdfReaderRef.current?._pdfDocument.setAnnotationMarkState(
annotation,
CPDFAnnotationMarkState.MARKED
);
const replies = await pdfReaderRef.current?._pdfDocument
.getAnnotationReplies(annotation);
if (replies?.length) {
await pdfReaderRef.current?._pdfDocument.setAnnotationMarkState(
replies[0],
CPDFAnnotationMarkState.UNMARKED
);
}
Gets the mark state of an annotation or annotation reply.
The annotation or reply annotation to query.
The current mark state.
Sets the review state of an annotation or annotation reply.
The annotation or reply annotation to update.
The review state.
true when the state was updated.
await pdfReaderRef.current?._pdfDocument.setAnnotationReviewState(
annotation,
CPDFAnnotationReviewState.ACCEPTED
);
const replies = await pdfReaderRef.current?._pdfDocument
.getAnnotationReplies(annotation);
if (replies?.length) {
await pdfReaderRef.current?._pdfDocument.setAnnotationReviewState(
replies[0],
CPDFAnnotationReviewState.COMPLETED
);
}
Gets the review state of an annotation or annotation reply.
The annotation or reply annotation to query.
The current review state.
Renders the current appearance of an annotation to a base64-encoded image string.
This API renders the annotation appearance from the PDF page. It does not return the original source asset for annotations backed by external content.
const page = pdfReaderRef.current?._pdfDocument.pageAtIndex(0);
const annotations = await page?.getAnnotations();
const annotation = annotations?.[0];
if (annotation) {
const base64 = await pdfReaderRef.current?._pdfDocument.renderAnnotationAppearance(
annotation,
{
scale: 4,
compression: CPDFPageCompression.PNG,
}
);
}
Updates the specified annotation in the document. For modifiable properties, please refer to the update method of CPDFAnnotation and its subclasses.
The annotation to be updated.
A promise that resolves when the operation completes.
// update markup annotation
const markupAnnotation = annotation as CPDFMarkupAnnotation;
markupAnnotation.update({
title: 'ComPDFKit',
content: 'Updated content',
markupText: 'Updated markup text',
color: '#FF0000',
alpha: 255
});
await pdfReaderRef.current?._pdfDocument.updateAnnotation(annotation);
Adds annotations to the document.
The annotations to add to the document.
A promise that resolves when the operation completes.
const annotations: CPDFAnnotation[] = [
new CPDFNoteAnnotation({
page: 0,
rect: { left: 100, top: 100, right: 150, bottom: 150 },
contents: 'This is a note annotation',
color: '#FFFF00',
}),
new CPDFMarkupAnnotation({
page: 1,
rect: { left: 50, top: 50, right: 200, bottom: 100 },
markupText: 'Highlighted text',
type: 'highlight',
color: '#00FF00',
}),
];
await pdfReaderRef.current?._pdfDocument.addAnnotations(annotations);
Gets the outline root of the document.
A promise that resolves to the outline root, or null when no outline is available.
if document has no outline, create a new outline root.
A promise that resolves to the newly created outline root, or null if it cannot be created.
Adds a new outline item under the given parent.
UUID of parent outline.
Title of the new outline.
Insert position within parent's children. Use -1 to append.
Target page index for the outline destination.
Moves an outline under a new parent by UUID.
UUID of outline to move.
UUID of the new parent outline (empty string for root).
Insert position within new parent's children. Use -1 to append.
Retrieves all bookmarks in the current document.
A promise that resolves to an array of CPDFBookmark objects.
Removes a bookmark at the specified page index.
The index of the page whose bookmark should be removed.
A promise that resolves to true if the bookmark was successfully removed, otherwise false.
Checks if a bookmark exists at the specified page index.
The index of the page to check for a bookmark.
A promise that resolves to whether the specified page has a bookmark.
Adds a bookmark at the specified page index with the given title.
The title of the bookmark to be added.
The index of the page where the bookmark should be added.
A promise that resolves to true if the bookmark was successfully added, otherwise false.
Updates an existing bookmark with new title and page index.
The bookmark object containing updated information.
A promise that resolves to true if the bookmark was successfully updated, otherwise false.
Removes the specified edit area from the document.
The edit area to be removed.
A promise that resolves when the operation completes.
// first addEventListener to listen for edit area selected event
pdfReaderRef.current?.addEventListener('onEditAreaSelected', (editArea : CPDFEditArea) => {
// store the selected edit area
this.selectedEditArea = editArea;
});
// then remove the selected edit area
await pdfReaderRef.current?.removeEditArea(editArea);
Creates a new text area in the content editor on the specified page. This method is only supported on the Android platform.
Configuration options for the new text area
The index of the page where the text area will be created
The text content to display
The position (x, y) where the text area will be placed
OptionalmaxWidth?: numberOptional maximum width of the text area
Optionalattr?: CPDFEditorTextAttrOptional text attributes (font color, size, alignment, etc.)
true if the text area was created successfully, otherwise false
Creates a new image area in the content editor on the specified page. This method is only supported on the Android platform.
Configuration options for the new image area
The index of the page where the image area will be created
The CPDFImageData instance containing the image source
The position (x, y) where the image area will be placed
Optionalwidth?: numberOptional width of the image area (default: 200)
true if the image area was created successfully, otherwise false
- Android Assets Path:
const imageData = CPDFImageData.fromAsset('image.png');
- Android Content URI:
const imageData = CPDFImageData.fromUri('content://media/external/images/media/12345');
- Android File Path:
const imageData = CPDFImageData.fromPath('/storage/emulated/0/Download/image.png');
- iOS File Path:
const imageData = CPDFImageData.fromPath('/var/mobile/Containers/Data/Application/.../Documents/image.png');
- Base64 String:
const imageData = CPDFImageData.fromBase64('iVBORw0KGgoAAAANSUhEUgAAAAUA...');
await pdfReaderRef.current?._pdfDocument.createNewImageArea({
pageIndex: 0,
imageData: imageData,
offset: { x: 100, y: 100 },
width: 200
});
Gets the current document's permissions. There are three types of permissions: No restrictions: [CPDFDocumentPermissions.NONE] If the document has an open password and an owner password, using the open password will grant [CPDFDocumentPermissions.USER] permissions, and using the owner password will grant [CPDFDocumentPermissions.OWNER] permissions.
A promise that resolves to the permissions available for the current document.
Retrieves the path of the current document. On Android, if the document was opened via a URI, the URI will be returned.
This function returns the path of the document being viewed. If the document was opened through a file URI on Android, the URI string will be returned instead of a file path.
A promise that resolves to the path (or URI) of the current document. If the native view reference is not found, the promise will be rejected with an error.
Gets the document information, such as title, author, subject, keywords, creation date, modification date, and producer.
A promise that resolves to a CPDFInfo object containing the document information.
Gets permission information of document, including whether printing, copying, modifying, annotating, filling forms, etc. are allowed.
a Promise that resolves to the CPDFDocumentPermissionInfo object.
Reopens a specified document in the current CPDFReaderView component.
The file path of the PDF document.
document = 'file:///storage/emulated/0/Download/sample.pdf'
document = 'content://...'
document = "file:///android_asset/..."
The password for the document, which can be null or empty.
A promise that resolves to true if the document is successfully opened, otherwise false.
Checks whether the document has been modified
Returns a Promise indicating if the document has been modified.
true: The document has been modified,
false: The document has not been modified.
If the native view reference cannot be found, a rejected Promise will be returned.
Removes a form widget from the current page.
The widget to be removed.
A promise that resolves to the requested state.
Adds an image signature to the widget.
The path of the image to be added as a signature.
A promise that resolves to true when the signature image is added; otherwise, false.
Updates the appearance of the specified widget.
The form widget whose properties or appearance will be updated.
A promise that resolves to true when the widget appearance is updated; otherwise, false.
Adds form widgets to the document.
The form widgets to add to the document.
A promise that resolves when the operation completes.
const widgets = [
new CPDFCheckboxWidget({
title: CPDFWidgetUtil.createFieldName("Checkbox"),
page: 0,
rect: { left: 361, top: 778, right: 442, bottom: 704 },
isChecked: true,
checkStyle: CPDFCheckStyle.CIRCLE,
checkColor: "#3CE930",
fillColor: "#e0e0e0",
borderColor: "#000000",
borderWidth: 5,
})
];
await pdfReaderRef.current?._pdfDocument.addWidgets(widgets);
Extracts images from the current document into the specified output directory.
The output path is a directory, not a single file path. The SDK writes images directly into this directory, creates it when needed, and does not clear existing files or create an extra child directory for each call.
The actual output directory where extracted images are saved.
Zero-based page indexes. Empty or null means all pages.
A structured result containing success, count, directoryPath, and imagePaths.
Imports annotations from the specified XFDF file into the current PDF document.
Path of the XFDF file to be imported.
true if the import is successful; otherwise, false.
// Android - assets file
const testXfdf = 'file:///android_asset/test.xfdf';
const importResult = await pdfReaderRef.current?._pdfDocument.importAnnotations(testXfdf);
// Android - file path
const testXfdf = '/data/user/0/com.compdfkit.reactnative.example/xxx/xxx.xfdf';
const importResult = await pdfReaderRef.current?._pdfDocument.importAnnotations(testXfdf);
// Android - Uri
const xfdfUri = 'content://xxxx'
const importResult = await pdfReaderRef.current?._pdfDocument.importAnnotations(xfdfUri);
// iOS
Imports the form data from the specified XFDF file into the current PDF document.
Path of the XFDF file to be imported.
true if the import is successful; otherwise, false.
Flatten all pages of the current document
The path to save the flattened document. On Android, you can pass a Uri.
Whether to include the font subset when saving.
Returns 'true' if the flattened document is saved successfully, otherwise 'false'.
const savePath = 'file:///storage/emulated/0/Download/flatten.pdf';
// or use Uri on the Android Platform.
const savePath = await ComPDFKit.createUri('flatten_test.pdf', 'compdfkit', 'application/pdf');
const fontSubset = true;
const result = await pdfReaderRef.current?._pdfDocument.flattenAllPages(savePath, fontSubset);
await pdfReaderRef.current?.reloadPagesPreservingPosition();
Saves the document to the specified directory.
Specifies the path where the document should be saved.
On Android, both file paths and URIs are supported. For example:
- File path: `/data/user/0/com.compdfkit.flutter.example/cache/temp/PDF_Document.pdf`
- URI: `content://media/external/file/1000045118`
Whether to remove the document's password.
Whether to embed font subsets into PDF. Defaults to true.
Returns 'true' if the document is saved successfully, otherwise 'false'.
Imports another PDF document and inserts it at a specified position in the current document.
This method imports an external PDF document into the current document, allowing you to choose which pages to import and where to insert the document.
The path of the PDF document to import. Must be a valid, accessible path on the device.
The collection of pages to import, represented as an array of integers. If null or an empty array is passed, the entire document will be imported.
The position to insert the external document into the current document. This value must be provided. If not specified, the document will be inserted at the end of the current document.
The password for the document, if it is encrypted. If the document is not encrypted, an empty string '' can be passed.
Returns a Promise<boolean> indicating whether the document import was successful.
true indicates successfalse or an error indicates failureconst filePath = '/data/user/0/com.compdfkit.flutter.example/cache/temp/PDF_Document.pdf';
const pages = [0]; // The pages to import from the document
const insertPosition = 0; // The position to insert, 0 means insert at the beginning of the document
const password = ''; // The password for the document, if encrypted
const importResult = await pdfReaderRef.current?._pdfDocument.importDocument(filePath, pages, insertPosition, password);
Splits the specified pages from the current document and saves them as a new document.
This function extracts the given pages from the current PDF document and saves them as a new document at the provided save path.
The path where the new document will be saved.
The array of page numbers to be extracted and saved in the new document.
A Promise that resolves to true if the operation is successful, or false if it fails.
Get the page object at the specified index
The index of the page to retrieve
The page object at the specified index
Inserts a blank page at the specified index in the document.
This method allows adding a blank page of a specified size at a specific index within the PDF document. It is useful for document editing scenarios where page insertion is needed.
The index position where the blank page will be inserted. Must be a valid index within the document.
The size of the blank page to insert. Defaults to A4 size if not specified.
Custom page sizes can be used by creating an instance of CPDFPageSize with custom dimensions.
A Promise that resolves to a boolean value indicating the success or failure of the blank page insertion.
Resolves to true if the insertion was successful, false otherwise.
Inserts an image as a new page into the current document at the specified index.
The image will be placed on a blank page with the given dimensions. The imagePath should point to a valid image resource accessible by the native platform (for example, a file path, content URI on Android, or bundled asset path).
Zero-based index at which the new image page will be inserted. Must be a valid index within the document (inserting at 0 places the page at the beginning).
Path or URI to the image to be inserted (platform-dependent). The image format should be supported by the underlying platform (e.g., PNG, JPEG).
The size of the page to create for the image. Defaults to A4 size if not provided.
A Promise that resolves to true if the image page was successfully inserted, or false if the operation failed.
// Android file path:
const imagePath = 'file:///storage/emulated/0/Download/photo.jpg';
// Android content URI:
const imagePath = 'content://media/external/images/media/12345';
// Android asset path:
const imagePath = 'file:///assets/photo.jpg';
// iOS file path:
const imagePath = 'var/mobile/Containers/Data/Application/.../Documents/photo.jpg';
// insert image page at index 2
const success = await pdfReaderRef.current?._pdfDocument.insertImagePage(2, imagePath, CPDFPageSize.custom(imageWidth, imageHeight));
// need reload pages after inserting image page.
if (success) {
await pdfReaderRef.current?.reloadPagesPreservingPosition();
}
Removes the pages at the specified indices from the current document.
The provided array should contain zero-based page indices to remove. Behavior for duplicate indices or out-of-range indices depends on the native implementation; callers should ensure indices are valid and unique where possible.
An array of zero-based page indices identifying the pages to remove.
A Promise that resolves to true if the pages were successfully removed, or false on failure.
Copies a page and inserts the duplicated page at the target index.
Both indexes are zero-based. pageIndex must point to an existing page.
insertIndex accepts 0..pageCount, and -1 appends the copied page to
the end of the current document.
The zero-based index of the source page to duplicate.
The zero-based insertion index for the copied page, or -1 to append.
A Promise that resolves to true if the page was copied successfully, or false otherwise.
Moves a page from one index to another within the current document.
This operation reorders pages so that the page originally at fromIndex will be placed
at toIndex. Both indices are zero-based. If toIndex is greater than the current page
count or either index is invalid, the operation may fail.
The zero-based index of the page to move.
The zero-based target index where the page should be inserted.
A Promise that resolves to true if the page was moved successfully, or false if the operation failed.
Gets the size of the specified page.
The index of the page (0-based).
The size of the specified page as a CPDFPageSize object.
Renders a PDF page into a base64-encoded image string.
Converts the specified page of the currently loaded PDF document into an image with the given dimensions, background color, and optional annotations or form fields. Useful for generating page thumbnails or exporting a page snapshot.
Rendering options
The index of the page to render (0-based).
The width of the rendered image in pixels.
The height of the rendered image in pixels.
OptionalbackgroundColor?: `#${string}`The background color of the rendered page. Only supported on Android.
OptionaldrawAnnot?: booleanWhether to draw annotations on the page. Only supported on Android.
OptionaldrawForm?: booleanWhether to draw form fields on the page. Only supported on Android.
OptionalpageCompression?: CPDFPageCompressionThe compression format used for rendering (e.g., PNG or JPEG).
A Promise that resolves to a base64-encoded image string.
const size = await pdfReaderRef.current?._pdfDocument.getPageSize(pageIndex);
const image = await pdfReaderRef.current?._pdfDocument.renderPage({
pageIndex,
width: size.width,
height: size.height,
backgroundColor: '#FFFFFF',
drawAnnot: true,
drawForm: true,
});
console.log(image); // iVBORw0KGgo...
Whether the owner password is correct. If the password is correct, the document will be unlocked with full owner permissions.
password The owner password to be verified.
A promise that resolves to true if the owner password is correct, otherwise false.
This method sets the document password, including the user password for access restrictions and the owner password for granting permissions.
The user password for document access restrictions.
The owner password to grant permissions (e.g., printing, copying).
Whether printing is allowed (true or false).
Whether copying is allowed (true or false).
The encryption algorithm to use (e.g., CPDFDocumentEncryptAlgo.rc4).
A promise that resolves to true if the password is successfully set, otherwise false.
Get the text searcher for the current document.
The text searcher instance for the current document.
Creates a document watermark. This changes the current document in memory and does not save it to disk automatically.
Returns a watermark at the given 0-based index, or null when not found.
Returns all watermarks in the current document.
Updates the watermark at the given 0-based index.
Provides document-level operations for the PDF reader.
Since
3.0.0
Remarks
Operations that require a mounted native reader reject when the reader reference is unavailable.