Skip to content

Commit 1c8011d

Browse files
committed
Text Annotation
1 parent 7f6153b commit 1c8011d

File tree

5 files changed

+135
-3
lines changed

5 files changed

+135
-3
lines changed
28.3 KB
Loading
4.08 KB
Loading
10 KB
Loading

libraries/radpdfprocessing/model/annotations/overview.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,25 @@ position: 0
99

1010
# Annotations Overview
1111

12-
The abstract __Annotation__ element associates an object with a location on a [RadFixedPage]({%slug radpdfprocessing-model-radfixedpage%}). Annotation exposes the following properties:
12+
An *annotation* associates an object such as a note, sound, or movie with a location on a page of a PDF document, or provides a way to interact with the user by
13+
means of the mouse and keyboard. PDF includes a wide variety of standard [annotation types](https://docs.telerik.com/devtools/document-processing/api/Telerik.Windows.Documents.Fixed.Model.Annotations.AnnotationType.html). Many of the standard annotation types may be displayed in either the open or the closed state. When closed, they appear on the page in some distinctive form, such as an icon, a box, or a rubber stamp, depending on the specific annotation type. When the user activates the annotation by clicking it, it exhibits its associated object, such as by opening a pop-up window displaying a text note or by playing a sound or a movie.
14+
15+
The abstract **Annotation** element associates an object with a location on a [RadFixedPage]({%slug radpdfprocessing-model-radfixedpage%}). Annotation exposes the following properties:
1316

14-
* __Rect__: The rectangle, which defines the location of the annotation on the page.
17+
* **Rect**: The rectangle, which defines the location of the annotation on the page.
1518

16-
* __Type__: Property of type [AnnotationType](https://docs.telerik.com/devtools/document-processing/api/Telerik.Windows.Documents.Fixed.Model.Annotations.AnnotationType.html), which determines the type of the annotation. The only supported types are [Link]({%slug radpdfprocessing-model-annotations-links%}) and [Widget]({%slug radpdfprocessing-model-annotations-widgets%}).
19+
* **Type**: Property of type [AnnotationType](https://docs.telerik.com/devtools/document-processing/api/Telerik.Windows.Documents.Fixed.Model.Annotations.AnnotationType.html), which determines the type of the annotation. The supported types are listed in the following table:
20+
21+
|Annotation Type|Description|
22+
|----|----|
23+
|[Link]({%slug radpdfprocessing-model-annotations-links%})|A link annotation represents either a hypertext link to a destination elsewhere in the document or an action to be performed.|
24+
|[Widget]({%slug radpdfprocessing-model-annotations-widgets%})|Interactive forms use widget annotations to represent the appearance of fields and to manage user interactions.|
25+
|[Text]({%slug radpdfprocessing-model-annotations-text%})|A text annotation represents a *sticky note* attached to a point in the PDF document.|
26+
|Line||
27+
|Stamp||
28+
|TextMarkup| Text markup annotations appear as **Highlights**, **Underlines**, **Strikeouts** or **Squiggly** underlines in the text of a document. When opened, they display a pop-up window containing the text of the associated note.|
29+
30+
1731
1832
* **Border**: Represents the annotation borders. This property is of type [AnnotationBorder](https://docs.telerik.com/devtools/document-processing/api/Telerik.Windows.Documents.Fixed.Model.Annotations.AnnotationBorder.html).
1933

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
---
2+
title: Text
3+
page_title: Text Annotation
4+
slug: radpdfprocessing-model-annotations-text
5+
tags: annotations, overview, pdfprocessing, text
6+
published: True
7+
position: 3
8+
---
9+
10+
# Text Annotation
11+
12+
A **Text annotation** represents a *sticky note* attached to a point in the PDF document. When closed, the annotation appears as an icon; when opened, it displays a pop-up window containing the text of the note in a font and size chosen by the viewer application.
13+
14+
>note Text annotations do not scale and rotate with the page. They behave as if the NoZoom and NoRotate annotation flags were always set.
15+
16+
The **TextAnnotation** class is a derivative of the **MarkupAnnotation** (descendent of **ContentAnnotation**) and it exposes the following properties:
17+
18+
|Property|Description|
19+
|---|---|
20+
|**Opacity**|Gets or sets the opacity of the annotation.|
21+
|**Contents**|Gets or sets the text that shall be displayed for the annotation.|
22+
|**Color**|Gets or sets the color of the annotation.|
23+
|**Content**|Gets the source defining the visual content of the annotation. This content is with bigger priority compared to the annotation appearance characteristics and text properties and it is visualized by default when opening the exported document in some PDF viewer.|
24+
25+
26+
### Creating a TextAnnotation
27+
28+
```csharp
29+
string sampleText = "sample text here";
30+
RadFixedDocument fixedDocument = new RadFixedDocument();
31+
using (RadFixedDocumentEditor editor = new RadFixedDocumentEditor(fixedDocument))
32+
{
33+
editor.InsertRun(sampleText);
34+
}
35+
RadFixedPage page = fixedDocument.Pages[0];
36+
TextAnnotation annotation = page.Annotations.AddText(new Rect(200, 100, 200, 200));
37+
annotation.Contents = "This is a TextAnnotation";
38+
annotation.Opacity = 0.5;
39+
annotation.Color = new RgbColor(255, 0, 0); //Default RgbColor(255, 255, 255)
40+
```
41+
42+
![Create TextAnnotation](images/pdf-processing-create-textannotation.png)
43+
44+
### Creating a TextAnnotation with FixedContentEditor
45+
46+
The FixedContentEditor offers the public **DrawTextAnnotation** method which creates a new TextAnnotation and draws it with a specified size and text and can create a PopupAnnotation to go with it.
47+
48+
```csharp
49+
RadFixedDocument fixedDocument = new RadFixedDocument();
50+
FixedContentEditor editor = new FixedContentEditor(fixedDocument.Pages.AddPage());
51+
editor.Position.Translate(100, 100);
52+
Size annotationSize = new Size(50, 50);
53+
Size popupSize = new Size(250, 100);
54+
string text = "This is a TextAnnotation";
55+
bool addPopup = true;
56+
editor.DrawTextAnnotation(annotationSize, popupSize, text, addPopup);
57+
PopupAnnotation popupAnnotation = fixedDocument.Pages[0].Annotations[1] as PopupAnnotation;
58+
```
59+
60+
![Create TextAnnotation with Popup](images/pdf-processing-create-textannotation-with-popup.png)
61+
62+
### Creating a TextAnnotation with Appearance
63+
64+
The **AnnotationContentSource** class, accessed by the **Content** property of the annotation object, represents the [FormSource]({%slug radpdfprocessing-model-formsource%}) instances used for displaying the widget content. The following example shows how to change the annotation's visual appearance when the mouse is not interacting with the widget (**NormalContentSource**) and when the mouse is over the widget (**MouseOverContentSource**):
65+
66+
```csharp
67+
private RadFixedDocument CreateTextAnnotation()
68+
{
69+
RadFixedDocument fixedDocument = new RadFixedDocument();
70+
RadFixedPage page = fixedDocument.Pages.AddPage();
71+
72+
TextAnnotation annotation = page.Annotations.AddText(new Rect(100, 100, 100, 50));
73+
annotation.Contents = "This is a TextAnnotation";
74+
FormSource normalForm = new FormSource();
75+
CreateContentFormWithText(normalForm, "Hover me");
76+
FormSource hoverForm = new FormSource();
77+
CreateContentFormWithText(hoverForm, "Done");
78+
79+
annotation.Content.NormalContentSource = normalForm;
80+
annotation.Content.MouseOverContentSource = hoverForm;
81+
return fixedDocument;
82+
}
83+
84+
private static void CreateContentFormWithText(FormSource normalForm, string text)
85+
{
86+
Size s = new Size(100, 40);
87+
Random rand= new Random();
88+
normalForm.Size = s;
89+
90+
FixedContentEditor formEditor = new FixedContentEditor(normalForm);
91+
92+
using (formEditor.SaveProperties())
93+
{
94+
formEditor.GraphicProperties.IsFilled = true;
95+
formEditor.GraphicProperties.IsStroked = true;
96+
formEditor.GraphicProperties.StrokeThickness = 1;
97+
formEditor.GraphicProperties.StrokeColor = new RgbColor(255, 0, 0);
98+
formEditor.GraphicProperties.FillColor = new RgbColor(255, 255, 0);
99+
formEditor.GraphicProperties.StrokeDashArray = new double[] { 17, 4 };
100+
formEditor.DrawRectangle(new Rect(s));
101+
}
102+
103+
formEditor.TextProperties.FontSize = 10;
104+
formEditor.Position.Translate(10, 10);
105+
formEditor.DrawText(text);
106+
}
107+
```
108+
109+
![Create TextAnnotation with Appearance](images/pdf-processing-create-textannotation-with-appearance.gif)
110+
111+
It is possible to modify the content source displayed when the mouse button is pressed on the widget via the **MouseDownContentSource** property of the AnnotationContentSource.
112+
113+
## See Also
114+
115+
* [AcroForm]({%slug radpdfprocessing-model-interactive-forms-acroform %})
116+
* [FormField]({%slug radpdfprocessing-model-interactive-forms-form-fields%})
117+
* [Annotations Overview]({%slug radpdfprocessing-model-annotations-overview%})
118+
* [FormSource]({%slug radpdfprocessing-model-formsource%})

0 commit comments

Comments
 (0)