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 → dynamic
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

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:
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>
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.
flattenAllPages(String savePath, bool fontSubset) Future<bool>
Flatten all pages of the current document.
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:
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.
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.
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.
removeWidget(CPDFWidget widget) Future<bool>
Removes a widget from the current page.
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.
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.
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:
updateWidget(CPDFWidget widget) Future<bool>
Updates a widget on the document.

Operators

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

Static Methods

createInstance() Future<CPDFDocument>