Guides
Predefined Annotations
Predefined annotations allow you to set default annotation properties that will be automatically applied when creating new annotations. You can set predefined annotation properties through CPDFConfiguration or CPDFReaderWidgetController.
The following are examples of how to set predefined annotation properties:
Setting Predefined Annotation Properties with CPDFConfiguration
dart
CPDFReaderWidget(
document: widget.documentPath,
configuration: CPDFConfiguration(
annotationsConfig: const CPDFAnnotationsConfig(
initAttribute: CPDFAnnotAttribute(
noteAttr: CPDFTextAttr(
color: Colors.blue,
alpha: 255
),
highlightAttr: CPDFHighlightAttr(
color: Colors.yellow,
alpha: 200
),
freeTextAttr: CPDFFreetextAttr(
fontColor: Colors.black,
fontSize: 18,
fontColorAlpha: 255,
alignment: CPDFAlignment.left,
familyName: 'Helvetica',
styleName: 'Regular',
)
)
))
);For more annotation properties that can be predefined, please refer to the definition of the
CPDFAnnotAttributeclass.
Setting Predefined Annotation Properties with CPDFReaderWidgetController
dart
// Get the currently defined default annotation attributes
CPDFAnnotAttribute defaultStyle = await controller.fetchDefaultAnnotationStyle();
// Modify default properties
// Modify note annotation properties
CPDFNoteAttr noteAttr = defaultStyle.noteAttr.copyWith(
color: Colors.red,
alpha: 128,
);
await controller.updateDefaultAnnotationStyle(noteAttr);
// Modify Ink annotation properties
CPDFInkAttr inkAttr = defaultStyle.inkAttr.copyWith(
color: Colors.blue,
alpha: 200,
borderWidth: 5
);
await controller.updateDefaultAnnotationStyle(inkAttr);In addition, you can also modify default annotation properties through the properties panel dialog:
dart
await controller.showDefaultAnnotationPropertiesView(CPDFAnnotationType.highlight);