PDF Generation Template Editor
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
The ComPDF Flutter SDK supports deleting selected annotations through APIs. The steps to delete annotations are as follows:
CPDFReaderWidget or an instance of CPDFDocument).Example:
Using CPDFReaderWidget:
CPDFReaderWidgetController? _controller;
// Initialize CPDFReaderWidget and obtain the controller in the onCreated callback
CPDFReaderWidget(
document: documentPath,
configuration: CPDFConfiguration(),
onCreated: (controller) {
setState(() {
this._controller = controller;
});
},
)
// Delete the first annotation on the first page
CPDFPage page = _controller.document.pageAtIndex(0);
var pageAnnotations = await page.getAnnotations();
await page.removeAnnotation(pageAnnotations[0]);Using CPDFDocument:
// Create and open the document
CPDFDocument document = await CPDFDocument.createInstance();
var error = await document.open(pdfFilePath);
if (error == CPDFDocumentError.success) {
// Delete the first annotation on the first page
CPDFPage page = document.pageAtIndex(0);
var pageAnnotations = await page.getAnnotations();
await page.removeAnnotation(pageAnnotations[0]);
}Alternatively, you can delete all annotations in the current document by calling the removeAllAnnotations() method.
Example:
Using CPDFReaderWidget:
CPDFReaderWidgetController? _controller;
// Initialize CPDFReaderWidget and obtain the controller in the onCreated callback
CPDFReaderWidget(
document: documentPath,
configuration: CPDFConfiguration(),
onCreated: (controller) {
setState(() {
this._controller = controller;
});
},
)
// Delete all annotations
bool deleteResult = await _controller.document.removeAllAnnotations();Using CPDFDocument:
// Create and open the document
CPDFDocument document = await CPDFDocument.createInstance();
var error = await document.open(pdfFilePath);
if (error == CPDFDocumentError.success) {
// Delete all annotations
bool deleteResult = await document.removeAllAnnotations();
}Note: This method does not remove link annotations.