Some test text!

Search
Hamburger Icon

Xamarin / Guides / Default annotation properties

Default annotation properties

Annotation properties have default settings and can be changed programmatically.

Setting default annotation properties in Xamarin.Android viewer

This tutorial only applies to Xamarin.Android. See Xamarin.iOS equivalent here .
## Programmatically When creating a new annotation, the initial properties (such as line thickness, fill color, opacity, etc.) are set to the last value that the user selected for an annotation of that type. For example, if the user changes an ellipse annotation's stroke color from green to red, the next ellipse annotation that the user creates would have a stroke color of red. These default properties are saved in the app's [SharedPreferences](https://developer.android.com/reference/android/content/SharedPreferences).

These default properties can be changed programmatically and will take effect the next time when the annotation is created.

For example, to change style properties of a rectangle:

var tool = (RectCreate) toolManager.createTool(ToolManager.ToolMode.RectCreate, null);
tool.SetupAnnotProperty(
    Color.Green,
    ToolStyleConfig.Instance.GetCustomOpacity(pdfViewCtrl.Context, (int)Annot.Type.e_Square, ""),
    ToolStyleConfig.Instance.GetCustomThickness(pdfViewCtrl.Context, (int)Annot.Type.e_Square, ""),
    Color.RED,
    null, null
);

where toolManager is an instance of ToolManager.

A table for annotation type and tool mode mapping can be found here: annotation and its creation tool.

XML attributes

Each annotation has a default style that is defined by its creation tool. For example, when you create a Square annotation using the tool for the first time, the default behavior to draw a rectangle with a red border and a transparent fill color. These default colors can changed through XML attributes.

However the effect will only take place when the app is first loaded.

Set a tool's default style

  1. Add a style to your styles.xml file. For details on supported style attributes, see Tool Style Attributes.

    <style name="ShapeProperty">
        <!-- border color -->
        <item name="annot_color">@android:color/white</item>
        <!-- fill color -->
        <item name="annot_fill_color">@android:color/white</item>
        <!-- thickness -->
        <item name="annot_thickness">1.0</item>
        <!-- opacity -->
        <item name="annot_opacity">1.0</item>
    </style>
2. Add the style resource to [`ToolStyleConfig`](/api/xamarinandroid/tools/api/pdftron.PDF.Config.ToolStyleConfig.html) by calling [`AddDefaultStyleMap(Int32, Int32)`](/api/xamarinandroid/tools/api/pdftron.PDF.Config.ToolStyleConfig.html#pdftron_PDF_Config_ToolStyleConfig_AddDefaultStyleMap_System_Int32_System_Int32_).
<div class='info'>
<div class='body'>The first parameter of addDefaultStyleMap is an annotation type. You can determine the annotation type from the creator tool by referring to the <a href="@@tools.tool-manager-android.annot-list">Table of annotations and its creation tool</a>.</div>
</div>
```java //@data {"m":true}// // Add the R.style.ShapeProperty to RectCreate tool. // Since the RectCreate tool creates a Square annotation, the annotation type of a Square // annotation is Annot.e_Square ToolStyleConfig.getInstance().addDefaultStyleMap(Annot.e_Square, R.style.ShapeProperty); ```

Tool style attributes

####annot_color Annotation color. For annotations that have an annot_fill_color, it represents stroke color.

format: color

####annot_text_color Annotation text color. Used for FreeText annotations.

format: color

annot_fill_color

Annotation fill color. Used for annotations that have fill colors, including Square, Circle, and FreeText.

format: color

annot_font_size

Annotation font size. Used for FreeText annotations.

format: float

annot_text_size_max

Represents a FreeText annotation's maximum font size.

format: float

annot_text_size_min

Represents a FreeText annotation's minimum font size.

format: float

annot_thickness

Annotation thickness for border style

format: float

annot_thickness_max

Annotation maximum thickness

format: float

annot_thickness_min

Annotation minimum thickness

format: float

annot_font

Annotation font. Used for FreeText annotations.

format: string

annot_opacity

Annotation opacity

format: float

annot_icon

Annotation icon. Used for Text annotations.

format: string

Trial setup questions? Ask experts on Discord
Need other help? Contact Support
Pricing or product questions? Contact Sales