CPDFDocument class document

A class to handle PDF documents without using CPDFReaderWidget

example:

var document = CPDFDocument();
document.open('pdf file path', 'password');

/// get pdf document info.
var info = await document.getInfo();

/// get pdf document file name.
var fileName = await document.getFileName();

Constructors

CPDFDocument.withController(int viewId)

Properties

hashCode → int
The hash code for this object.
no setterinherited
isValid → bool
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

addAnnotationReply(CPDFAnnotation annotation, {required String content, String title = ''}) → Future<CPDFReplyAnnotation?>
Adds a plain reply to an annotation.
addAnnotations(List<CPDFAnnotation> annotations) → Future<bool>
Adds annotations to the document.
addBookmark({required String title, required int pageIndex}) → Future<bool>
Adds a bookmark with the specified title and page index. Parameters:
addOutline({required String parentUuid, int insertIndex = -1, required String title, required int pageIndex}) → Future<bool>
Adds an outline to the current document. Parameters:
addSignatureImage(CPDFSignatureWidget signatureWidget, String imagePath) → Future<bool>
Adds an image signature to a signature form widget.
addWidgets(List<CPDFWidget> widgets) → Future<bool>
Adds widgets to the document.
checkOwnerPassword(String password) → Future<bool>
Whether the owner password is correct.
checkOwnerUnlocked() → Future<bool>
Check if owner permissions are unlocked
close() → Future<void>
copyPage({required int pageIndex, required int insertIndex}) → Future<bool>
Copies a page in the current document and inserts the copy at the specified index.
createNewImageArea({required int pageIndex, required CPDFImageData imageData, required Offset offset, double width = 200}) → Future<bool>
Inserts a new image area on the specified page.
createNewTextArea({required int pageIndex, required String content, required Offset offset, double? maxWidth, CPDFEditorTextAttr attr = const CPDFEditorTextAttr()}) → Future<bool>
Inserts a new text area on the specified page.
createWatermark(CPDFWatermark watermark) → Future<bool>
Create document watermarks, including text watermarks and image watermarks
exportAnnotations() → Future<String>
Exports annotations from the current PDF document to an XFDF file.
exportWidgets() → Future<String>
exports the form data from the current PDF document to an XFDF file.
extractImages({required String directoryPath, List<int>? pages}) → Future<CPDFExtractImageResult>
Extracts images from the current PDF document into a directory.
flattenAllPages(String savePath, bool fontSubset) → Future<bool>
Flatten all pages of the current document.
getAnnotationMarkState(CPDFAnnotation annotation) → Future<CPDFAnnotationMarkState>
Gets the mark state of an annotation or annotation reply.
getAnnotationReplies(CPDFAnnotation annotation) → Future<List<CPDFReplyAnnotation>>
Gets all replies attached to an annotation.
getAnnotationReviewState(CPDFAnnotation annotation) → Future<CPDFAnnotationReviewState>
Gets the review state of an annotation or annotation reply.
getBookmarks() → Future<List<CPDFBookmark>>
Gets the bookmarks of the current document. example:
getDocumentPath() → Future<String>
Get the path of the current document.
getEncryptAlgo() → Future<CPDFDocumentEncryptAlgo>
Get the encryption algorithm of the current document
getFileName() → Future<String>
Gets the file name of the PDF document.
getInfo() → Future<CPDFInfo>
Gets the document information, such as title, author, subject, keywords, creation date, modification date, and producer. This method retrieves metadata about the PDF document. example:
getMajorVersion() → Future<int>
Gets major version string of document. example:
getMinorVersion() → Future<int>
Gets minor version string of document. example:
getOutlineRoot() → Future<CPDFOutline?>
Gets the outline data of the current document.
getPageCount() → Future<int>
Get the total number of pages in the current document
getPageSize(int pageIndex) → Future<Size>
Gets the size of the specified page in the document. This method retrieves the dimensions of a page at the given index. Parameters:
getPermissions() → Future<CPDFDocumentPermissions>
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.
getPermissionsInfo() → Future<CPDFDocumentPermissionInfo>
Gets permission information of document, including whether printing, copying, and modifying are allowed. example:
getTextSearcher() → CPDFTextSearcher
Gets the text searcher for the document. This method returns an instance of CPDFTextSearcher that can be used to perform text searches within the PDF document. example:
getWatermark(int index, {bool exportImage = false}) → Future<CPDFWatermark?>
Gets the watermark at index.
getWatermarkCount() → Future<int>
Gets the number of watermarks in the current document.
getWatermarks({bool exportImages = false}) → Future<List<CPDFWatermark>>
Gets all watermarks in the current document.
hasBookmark(int pageIndex) → Future<bool>
Checks if a bookmark exists for the specified page index.
hasChange() → Future<bool>
Check the document for modifications
importAnnotations(String xfdfFile) → Future<bool>
Imports annotations from the specified XFDF file into the current PDF document.
importDocument({required String filePath, List<int> pages = const [], int insertPosition = -1, String? password}) → Future<bool>
Imports another PDF document and inserts it at a specified position in the current document.
importWidgets(String xfdfFile) → Future<bool>
Imports the form data from the specified XFDF file into the current PDF document.
xfdfFile The path or URI of the XFDF file to import.
insertBlankPage({required int pageIndex, CPDFPageSize pageSize = CPDFPageSize.a4}) → Future<bool>
Inserts a blank page at the specified index in the document.
insertPageWithImagePath({required int pageIndex, required String imagePath, CPDFPageSize pageSize = CPDFPageSize.a4}) → Future<bool>
Inserts a new PDF page at the specified index using an image from a file path.
isEncrypted() → Future<bool>
Checks if the PDF document is encrypted.
isImageDoc() → Future<bool>
Checks if the PDF document is an image document. This is a time-consuming operation that depends on the document size.
isLocked() → Future<bool>
moveOutline({required CPDFOutline outline, required CPDFOutline newParent, int insertIndex = -1}) → Future<bool>
Moves the specified outline to a new parent outline at the given insert position.
movePage({required int fromIndex, required int toIndex}) → Future<bool>
Moves a page from one index to another within the document. Parameters:
newOutlineRoot() → Future<CPDFOutline?>
Creates a new outline root for the current document. example:
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
open(String filePath, {String password = ''}) → Future<CPDFDocumentError>
pageAtIndex(int pageIndex) → CPDFPage
Get the page object at the specified index. pageIndex The index of the page to retrieve.
printDocument() → Future<void>
Invokes the system's print service to print the current document.
removeAllAnnotationReplies(CPDFAnnotation annotation) → Future<bool>
Removes all plain replies attached to an annotation.
removeAllAnnotations() → Future<bool>
Delete all comments in the current document
removeAllWatermarks() → Future<void>
remove all watermark
removeAnnotation(CPDFAnnotation annotation) → Future<bool>
Removes an annotation from the current page.
removeAnnotationReply(CPDFReplyAnnotation reply) → Future<bool>
Removes a plain annotation reply.
removeBookmark(int pageIndex) → Future<bool>
remove a bookmark by its page index.
removeEditArea(CPDFEditArea editArea) → Future<bool>
Removes an edit area from the document.
removeOutline(String uuid) → Future<bool>
Removes an outline from the current document by its UUID. Parameters:
removePages(List<int> pageIndexes) → Future<bool>
Removes pages at the specified indexes from the document. This method allows you to delete multiple pages from the PDF document by providing a list of page indexes. Parameters:
removePassword() → Future<bool>
Remove the user password and owner permission password set in the document, and perform an incremental save.
removeWatermark(int index) → Future<bool>
Removes the watermark at index.
removeWidget(CPDFWidget widget) → Future<bool>
Removes a widget from the current page.
renderAnnotationAppearance(CPDFAnnotation annotation, {CPDFAnnotationRenderOptions options = const CPDFAnnotationRenderOptions()}) → Future<Uint8List>
Renders the current appearance of an annotation to image bytes.
renderPage({required int pageIndex, required int width, required int height, Color backgroundColor = Colors.white, bool drawAnnot = true, bool drawForm = true, CPDFPageCompression compression = CPDFPageCompression.png}) → Future<Uint8List>
Renders a specific page of the document as an image. Parameters:
save({bool saveIncremental = true, bool fontSubSet = true}) → Future<bool>
Save document
saveAs(String savePath, {bool removeSecurity = false, bool fontSubSet = true}) → Future<bool>
Saves the document to the specified directory.
setAnnotationMarkState(CPDFAnnotation annotation, CPDFAnnotationMarkState state) → Future<bool>
Sets the mark state of an annotation or annotation reply.
setAnnotationReviewState(CPDFAnnotation annotation, CPDFAnnotationReviewState state) → Future<bool>
Sets the review state of an annotation or annotation reply.
setPassword({String? userPassword, String? ownerPassword, bool allowsPrinting = true, bool allowsCopying = true, CPDFDocumentEncryptAlgo encryptAlgo = CPDFDocumentEncryptAlgo.rc4}) → Future<bool>
This method sets the document password, including the user password for access restrictions and the owner password for granting permissions.
splitDocumentPages(String savePath, List<int> pages) → Future<bool>
Splits the specified pages from the current document and saves them as a new document.
toString() → String
A string representation of this object.
inherited
updateAnnotation(CPDFAnnotation annotation) → Future<bool>
Updates an annotation on the document.
updateAnnotationReply(CPDFReplyAnnotation reply, {required String content, String? title}) → Future<bool>
Updates a plain annotation reply.
updateBookmark(CPDFBookmark bookmark) → Future<bool>
Updates an existing bookmark with the specified title and page index. Parameters:
updateOutline({required String uuid, required dynamic title, required dynamic pageIndex}) → Future<bool>
Updates an existing outline in the current document. Parameters:
updateWatermark(int index, CPDFWatermark watermark) → Future<bool>
Updates the watermark at index.
updateWidget(CPDFWidget widget) → Future<bool>
Updates a widget on the document.

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Methods

createDocument() → Future<CPDFDocument>
Creates a new PDF document without opening an existing file or using CPDFReaderWidget.
createInstance() → Future<CPDFDocument>
Creates a document channel instance that can open an existing PDF file.