exportAnnotation method

List<int> exportAnnotation(
  1. PdfAnnotationDataFormat format, {
  2. String? fileName,
  3. List<PdfAnnotation>? exportList,
  4. List<PdfAnnotationExportType>? exportTypes,
  5. bool exportAppearance = false,
})

Export the annotation data to UTF8 bytes with the specific PdfAnnotationDataFormat.

To export specific annotations, annotation types, appearances, and add a file name to the export format, we can use the named parameters exportList, exportTypes, exportAppearance, and fileName respectively.

//Load an existing PDF document.
PdfDocument document =
    PdfDocument(inputBytes: File('input.pdf').readAsBytesSync());
//Export annotations in specific PdfAnnotationDataFormat format.
List<int> bytes = document.exportAnnotation(PdfAnnotationDataFormat.fdf,
    fileName: 'PDFExportDocument');
//Save the exported data.
File('export.fdf').writeAsBytesSync(bytes);
//Dispose the document.
document.dispose();

Implementation

List<int> exportAnnotation(PdfAnnotationDataFormat format,
    {String? fileName,
    List<PdfAnnotation>? exportList,
    List<PdfAnnotationExportType>? exportTypes,
    bool exportAppearance = false}) {
  List<int> bytes = <int>[];
  if (format == PdfAnnotationDataFormat.xfdf) {
    bytes = _helper.exportXfdf(
        fileName, exportList, exportTypes, exportAppearance);
  } else if (format == PdfAnnotationDataFormat.fdf) {
    bytes = _helper.exportFdf(
        fileName, exportList, exportTypes, exportAppearance);
  } else if (format == PdfAnnotationDataFormat.json) {
    bytes = _helper.exportJson(
        fileName, exportList, exportTypes, exportAppearance);
  }
  return bytes;
}