Configuring annotation presets in UWP

Annotation presets are sets of default properties assigned to each annotation button. With annotation presets, you can configure default values for annotation properties created with the annotation button — for example, default colors.

Annotation presets can be modified to use customized property values. These values will be updated by default when the user changes the settings in the annotation toolbar. It’s possible to disable update events if required.

Below, the line item preset is modified so that line annotations have a red color, are transparent, and have a thick stroke width by default:

// Get the `Dictionary` of `string` -> `IAnnotation` presets.
var presets = await pdfView.Controller.GetAnnotationPresetsAsync();
// We know "line" is a `Line` class.
var line = (Line)presets["line"];
// Change some defaults.
line.StrokeWidth = 10;
line.Opacity = 0.5f;
line.StrokeColor = Colors.Red;
// Set the preset.
await pdfView.Controller.SetAnnotationPresetAsync("line", line);

Preset name to annotation type table

NameAnnotation type
strikeoutPSPDFKit.Pdf.Annotation.Strikeout
arrowPSPDFKit.Pdf.Annotation.Line
underlinePSPDFKit.Pdf.Annotation.Underline
notePSPDFKit.Pdf.Annotation.Note
text-highlighterPSPDFKit.Pdf.Annotation.Highlight
ink-signaturePSPDFKit.Pdf.Annotation.Ink
imagePSPDFKit.Pdf.Annotation.Image
polygonPSPDFKit.Pdf.Annotation.Polygon
highlightPSPDFKit.Pdf.Annotation.Highlight
rectanglePSPDFKit.Pdf.Annotation.Rectangle
textPSPDFKit.Pdf.Annotation.Text
highlighterPSPDFKit.Pdf.Annotation.Ink
ellipsePSPDFKit.Pdf.Annotation.Ellipse
inkPSPDFKit.Pdf.Annotation.Ink
polylinePSPDFKit.Pdf.Annotation.Polyline
squigglePSPDFKit.Pdf.Annotation.Squiggly
linePSPDFKit.Pdf.Annotation.Line
redactionPSPDFKit.Pdf.Annotation.Redaction

Preset update events

The following code is taken from the example Catalog app provided with our SDK. It demonstrates how to register an event handler for preset changes made by the user in the annotation toolbar:

pdfView.Controller.OnAnnotationPresetUpdate += async (sender, annotation) =>
{
var from = await Json.StringifyAsync(annotation.Current);
var to = await Json.StringifyAsync(annotation.New);
Events.Add($"Preset updated for {annotation.Name} from:\n {from}\nTo:\n{to}");
};

Preset update events can be disabled. When disabled, any changes to the settings made by the user via the annotation toolbar won’t be preserved after the user is finished creating an annotation:

// Disable preset updating.
await pdfView.Controller.DisableAnnotationPresetUpdatingAsync(true);