DsPdf supports various types of annotation standardized by Adobe. The following section describes different types of annotations and their implementation.
Text annotation represents a sticky note attached to a point in a PDF file. Upon closing, the annotation appears as an icon, and upon opening, it displays a pop-up window with the text of the note, in a size and font as selected by the viewer application. DsPdf provides TextAnnotation class to enable the users to apply text annotations in the PDF document.
The following code illustrates how to add a text annotation to a PDF document.
C# |
Copy Code
|
---|---|
public void CreateTextAnnotation() { GcPdfDocument doc = new GcPdfDocument(); Page page = doc.NewPage(); RectangleF rc = new RectangleF(50, 50, 200, 50); page.Graphics.DrawString("A red text annotation initially open is placed to the right of this note.", new TextFormat() { Font = StandardFonts.Times, FontSize = 11 }, rc); //Create an instance of TextAnnotation class and set its relevant properties var textAnnot = new TextAnnotation() { UserName = "Jamie Smith", Contents = "This is a text annotation in red color.", PdfRect = new RectangleF(rc.Right, rc.Top, 72 * 2, 72), Color = Color.Red, Open = true }; page.Annotations.Add(textAnnot); //Add the text annotation doc.Save("TextAnnotation.pdf"); } |
A free text annotation displays text directly on the page. Unlike text annotations, the free text annotations do not have an open or closed state. The text remains visible instead of being displayed in a pop-up window. DsPdf provides FreeTextAnnotation class to enable the users to apply free text annotations to the PDF file.
The following code illustrates how to add a free text annotation to a PDF document.
C# |
Copy Code
|
---|---|
public void CreateFreeTextAnnotation() { GcPdfDocument doc = new GcPdfDocument(); Page page = doc.NewPage(); RectangleF rc = new RectangleF(50, 50, 200, 50); page.Graphics.DrawString ("A blue free text annotation is placed below and to the right, " + "with a callout going from it to this note", new TextFormat() { Font = StandardFonts.Times, FontSize = 11 }, rc); //Create an instance of FreeTextAnnotation class and set its relevant properties var freeAnnot = new FreeTextAnnotation() { PdfRect = new RectangleF(rc.Right + 18, rc.Bottom + 9, 72 * 2, 72), CalloutLine = new PointF[] { new PointF(rc.Left + rc.Width / 2, rc.Bottom), new PointF(rc.Left + rc.Width / 2, rc.Bottom + 9 + 36), new PointF(rc.Right + 18, rc.Bottom + 9 + 36), }, LineWidth = 1, LineEndStyle = LineEndingStyle.OpenArrow, LineDashPattern = new float[] { 8, 4 }, Contents = "This is a free text annotation with a callout line going to the note on the left.", Color = Color.LightSkyBlue, }; page.Annotations.Add(freeAnnot); //Add the free text annotation doc.Save("FreeTextAnnotation.pdf"); } |
A line annotation displays a single straight line on the page. Upon opening, the annotation displays a pop-up window containing the associated note. DsPdf provides LineAnnotation class to enable the users to apply line annotations to the PDF file.
The following code illustrates how to add a line annotation to a PDF document.
C# |
Copy Code
|
---|---|
public void CreateLineAnnotation() { GcPdfDocument doc = new GcPdfDocument(); Page page = doc.NewPage(); RectangleF rc = new RectangleF(50, 50, 250, 50); page.Graphics.DrawString ("A line annotation is drawn around this note which illustates the effect of including " + "leader lines and caption in a line annotation", new TextFormat() { Font = StandardFonts.Times, FontSize = 11 }, rc); //Create an instance of LineAnnotation class and set its relevant properties var lineAnnot = new LineAnnotation() { UserName = "Jaime Smith", Start = new PointF(rc.X, rc.Bottom), End = new PointF(rc.Right, rc.Bottom), LineWidth = 3, Color = Color.Red, LeaderLinesLength = -15, LeaderLinesExtension = 5, LeaderLineOffset = 10, Contents = "Line annotation", VerticalTextOffset = -20, TextPosition = LineAnnotationTextPosition.Inline, }; page.Annotations.Add(lineAnnot); //Add the square annotation doc.Save("LineAnnotation.pdf"); } |
A square annotation displays a rectangle/square on the page. When opened, the annotation displays a pop-up window with the text of the associated note. DsPdf provides SquareAnnotation class to enable the users to apply square annotations to the PDF file.
Note that square annotation need not always imply that the annotation is square in shape. The height and width of the annotation may vary. The image given below depicts a rectangle-shaped square annotation.
The following code illustrates how to add a square annotation to a PDF document.
C# |
Copy Code
|
---|---|
public void CreateSquareAnnotation() { GcPdfDocument doc = new GcPdfDocument(); Page page = doc.NewPage(); RectangleF rc = new RectangleF(50, 50, 250, 50); page.Graphics.DrawString ("A square annotation drawn with a 3pt wide orange line around this note has a rich text " + "associated with it.", new TextFormat() { Font = StandardFonts.Times, FontSize = 11 }, rc); rc.Inflate(10, 10); //Create an instance of SquareAnnotation class and set its relevant properties var squareAnnot = new SquareAnnotation() { UserName = "Jaime Smith", PdfRect = rc, LineWidth = 3, Color = Color.Orange, RichText = "<body><p>This <b><i>rich text</i></b> is associated with the square annotation around a text note.</p></body>" }; page.Annotations.Add(squareAnnot); //Add the square annotation doc.Save("SquareAnnotation.pdf"); } |
A circle annotation displays an ellipse/circle on a page. When open, the annotation displays a pop-up window with the text of the associated note. DsPdf provides CircleAnnotation class to enable the users to apply circle annotations to the PDF file.
Note that circle annotation need not always imply that the annotation is circular in shape. The height and width of the annotation may vary. The image given below depicts an ellipse-shaped circle annotation.
The following code illustrates how to add a circle annotation to a PDF document.
C# |
Copy Code
|
---|---|
public void CreateCircleAnnotation() { GcPdfDocument doc = new GcPdfDocument(); Page page = doc.NewPage(); RectangleF rc = new RectangleF(50, 50, 120, 50); page.Graphics.DrawString("A circle annotation drawn with a 3pt wide green line", new TextFormat() { Font = StandardFonts.Times, FontSize = 11 }, rc); rc.Inflate(15, 24); //Create an instance of CircleAnnotation class and set its relevant properties var circleAnnot = new CircleAnnotation() { UserName = "Jaime Smith", PdfRect = rc, LineWidth = 3, Color = Color.Green, Contents = "This is a circle annotation", }; page.Annotations.Add(circleAnnot); //Add the circle annotation doc.Save("CircleAnnotation.pdf"); } |
A polygon annotation displays a polygon on a page. On opening the annotation, it displays a pop-up window containing the text of the associated note. DsPdf provides PolygonAnnotation class to enable the users to apply polygon annotations to the PDF file.
The following code illustrates how to add a polygon annotation to a PDF document.
C# |
Copy Code
|
---|---|
public void CreatePolygonAnnotation() { GcPdfDocument doc = new GcPdfDocument(); Page page = doc.NewPage(); RectangleF rc = new RectangleF(140, 30, 160, 70); page.Graphics.DrawString("A polygon annotation drawn with a 3pt wide purple line around this note", new TextFormat() { Font = StandardFonts.Times, FontSize = 11 }, rc); //Create an instance of PolygonAnnotation class and set its relevant properties var polygonAnnot = new PolygonAnnotation() { Points = new List<PointF>() { new PointF(rc.X-5, rc.Y), new PointF(rc.X+75, rc.Y-10), new PointF(rc.X+rc.Width-5, rc.Y), new PointF(rc.X+rc.Width-5, rc.Y+rc.Height), new PointF(rc.X-5, rc.Y+rc.Height), }, UserName = "Jaime Smith", LineWidth = 3, LineDashPattern = new float[] { 5, 2, 15, 4 }, Color = Color.Purple, Contents = "This is a polygon annotation", }; page.Annotations.Add(polygonAnnot); //Add the polygon annotation doc.Save("PolygonAnnotation.pdf"); } |
A stamp annotation displays graphics, images or texts to look as if they were stamped on a page. Upon opening, the stamp annotations display a pop-up window with the text of the associated note. DsPdf provides StampAnnotation class to enable the users to apply stamp annotations to the PDF file.
The following code illustrates how to add a stamp annotation to a PDF document.
C# |
Copy Code
|
---|---|
public void CreateStampAnnotation() { GcPdfDocument doc = new GcPdfDocument(); var page = doc.NewPage(); //Create an instance of StampAnnotation class and set its relevant properties var stamp = new StampAnnotation() { Contents = "This is a sample stamp", UserName = "Jamie Smith", Color = Color.SkyBlue, Icon = StampAnnotationIcon.Confidential.ToString(), CreationDate = DateTime.Today, PdfRect = new RectangleF(100.5F, 110.5F, 72, 72), }; page.Annotations.Add(stamp); //Add the stamp annotation doc.Save("StampAnnotation.pdf"); } |
An ink annotation represents a freehand scribble composed of one or more disjoint paths. When an ink annotation is opened, it displays a pop-up window containing the text of the related note. DsPdf provides InkAnnotation class to enable the users to apply ink annotations to the PDF file.
The following code illustrates how to add an ink annotation to a PDF document.
C# |
Copy Code
|
---|---|
public void CreateInkAnnotation() { var doc = new GcPdfDocument(); var page = doc.NewPage(); RectangleF rc = new RectangleF(50, 50, 250, 50); page.Graphics.DrawString("This sample creates an ink annotation and shows how to use the " + "InkAnnotation.Paths property", new TextFormat() { Font = StandardFonts.Times, FontSize = 11 }, rc); //Create an instance of InkAnnotation class and set its relevant properties var inkAnnot = new InkAnnotation() { UserName = "Jaime Smith", PdfRect = new RectangleF(rc.Left, rc.Bottom + 20, 72 * 5, 72 * 2), LineWidth = 2, Color = Color.DarkBlue, Contents = "This is an ink annotation drawn via InkAnnotation.Paths." }; float x = 80, y = rc.Bottom + 24, h = 18, dx = 2, dy = 4, dx2 = 4, w = 10, xoff = 15; // Scribble 'ink annotation' text: // i List<PointF[]> paths = new List<PointF[]>(); paths.Add(new[] { new PointF(x + w / 2, y), new PointF(x + w / 2, y + h), new PointF(x + w, y + h * .7f) }); paths.Add(new[] { new PointF(x + w / 2, y), new PointF(x + w / 2, y + h), new PointF(x + w, y + h * .7f) }); paths.Add(new[] { new PointF(x + w / 2 - dx, y - h / 3 + dy), new PointF(x + w / 2 + dx, y - h / 3) }); // n x += xoff; paths.Add(new[] { new PointF(x, y), new PointF(x, y + h), new PointF(x, y + h - dy), new PointF(x + w*0.7f, y), new PointF(x + w - dx/2, y + h*.6f), new PointF(x + w, y + h), new PointF(x + w + dx2, y + h*.7f) }); // k x += xoff; paths.Add(new[] { new PointF(x, y - h / 3), new PointF(x, y + h) }); paths.Add(new[] { new PointF(x + w, y), new PointF(x + dx, y + h/2 - dy), new PointF(x, y + h/2), new PointF(x + dx2, y + h/2 + dy), new PointF(x + w, y + h), new PointF(x + w + dx2, y + h*.7f) }); inkAnnot.Paths = paths; page.Annotations.Add(inkAnnot); doc.Save("InkAnnotation.pdf"); } |
A file attachment annotation represents a reference to a file which typically is embedded in the PDF file. The file attachment annotation appears as a paper clip icon on the PDF file. Users can double-click the icon to open the embedded file. This gives users a chance to view or store the file in the system. DsPdf provides FileAttachmentAnnotation class to enable the users to apply file attachment annotations to the PDF file.
The following code illustrates how to add the file attachment annotation to a PDF document.
C# |
Copy Code
|
---|---|
public void CreateFileAttachmentAnnotation() { var doc = new GcPdfDocument(); var page = doc.NewPage(); var g = page.Graphics; RectangleF rc = new RectangleF(50, 50, 400, 80); g.DrawString("Some files from the sample's Resources/Images folder are attached to this page. Some viewers" + " may not show attachments, so we draw rectangles to indicate their(usually clickable) location", new TextFormat() { Font = StandardFonts.Times, FontSize = 11 }, rc); var ip = new PointF(rc.X, rc.Bottom + 9); var attSize = new SizeF(36, 12); var gap = 8; string[] files = new string[] { "tudor.jpg", "sea.jpg", "puffins.jpg", "lavender.jpg", }; foreach (string fn in files) { string file = Path.Combine("Resources", "Images", fn); //Create an instance of FileAttachmentAnnotation class and set its relevant properties FileAttachmentAnnotation faa = new FileAttachmentAnnotation() { Color = Color.FromArgb(unchecked((int)0xFFc540a5)), UserName = "Jaime Smith", PdfRect = new RectangleF(ip.X, ip.Y, attSize.Width, attSize.Height), Contents = "Attached file: " + file, Icon = FileAttachmentAnnotationIcon.Paperclip, File = FileSpecification.FromEmbeddedFile(EmbeddedFileStream.FromFile(doc, file)), }; page.Annotations.Add(faa); //Add the file attachment annotation g.FillRectangle(faa.Rect, Color.FromArgb(unchecked((int)0xFF40c5a3))); g.DrawRectangle(faa.Rect, Color.FromArgb(unchecked((int)0xFF6040c5))); ip.Y += attSize.Height + gap; } doc.Save("FileAttachmentAnnotation.pdf"); } |
RichMedia annotation is a reference to the media resources (audio and video) embedded in a PDF document. It will appear as a rectangular box with a play button inside. To add RichMedia annotations to the PDF document, DsPdf provides SetVideo, SetAudio, and SetContent methods of RichMediaAnnotation class.
DsPdf also provides helper classes RichMediaAnnotationActivation, RichMediaAnnotationDeactivation, and RichMediaAnnotationPresentationStyle with constants that define the following properties of RichMediaAnnotation class:
Property | Constants | Description |
---|---|---|
ActivationCondition | UserAction | The annotation is activated explicitly by a user action or script. |
PageReceivesFocus | The annotation activates as soon as the page that contains it receives focus as the current page. | |
PageBecomesVisible | The annotation activates as soon as any part of the page that contains the annotation becomes visible. | |
DeactivationCondition | UserAction | The annotation is deactivated explicitly by a user action or script. |
PageLosesFocus | The annotation deactivates as soon as the page that contains it loses focus as the current page. | |
PageBecomesInvisible | The annotation deactivates as soon as the entire page that contains the annotation is no longer visible. | |
PresentationStyle | Embedded | The media plays inside the viewer. |
Windowed | The media plays in a separate window. |
Refer to the following example code to add a video using RichMediaAnnotation:
C# |
Copy Code
|
---|---|
// Initialize GcPdfDocument. var doc = new GcPdfDocument(); // Add a blank page to the PDF document. var page = doc.NewPage(); // Initialize GcPdfGraphics. var g = page.Graphics; // Provide video path. var videoPath = Path.Combine("waterfall.mp4"); const int smallGap = 18; // Set text format. var tf = new TextFormat() { Font = StandardFonts.HelveticaBold, FontSize = 14 }; // Add a video that plays when the page becomes visible. var rc = new RectangleF(new PointF(60, 50), new SizeF(500, 10)); // Draw the introductory string. g.DrawString("The following video plays automatically when the page becomes visible:", tf, rc); // Initialize RichMediaAnnotation and set its properties. var rma = new RichMediaAnnotation(); var videoEfs = EmbeddedFileStream.FromFile(doc, videoPath); var videoFileSpec = FileSpecification.FromEmbeddedStream(Path.GetFileName(videoPath), videoEfs); // Set the media for the video. rma.SetVideo(videoFileSpec); // Set presentation style. rma.PresentationStyle = RichMediaAnnotationPresentationStyle.Embedded; // Set activation condition. rma.ActivationCondition = RichMediaAnnotationActivation.PageBecomesVisible; // Set deactivation condition. rma.DeactivationCondition = RichMediaAnnotationDeactivation.PageBecomesInvisible; // Set behavior of navigation pane. rma.ShowNavigationPane = true; // Set page to which RichMediaAnnotation will be added. rma.Page = page; // Set rectangle in which RichMediaAnnotation will be added. rma.Rect = new RectangleF(rc.X, rc.Bottom + smallGap, 72 * 5, 72 * 5 * 0.56f); // Save the document. doc.Save("RichMediaAnnotation.pdf"); |
User can also fetch the media from the RichMedia annotation using GetContent method of RichMediaAnnotation class.
Sound annotation is analogous to a text annotation except that instead of a text note, it contains sound (.au, .aiff, or .wav format) imported from a file or recorded from the computer’s microphone. DsPdf provides SoundAnnotation class to enable the users to apply sound annotations to the PDF file.
The following code illustrates how to add a sound annotation to a PDF document.
C# |
Copy Code
|
---|---|
public void CreateSoundAnnotation() { GcPdfDocument doc = new GcPdfDocument(); Page page = doc.NewPage(); RectangleF rc = new RectangleF(50, 50, 250, 50); page.Graphics.DrawString("A red sound annotation is placed to the right of this note. Double click " + "the icon to play the sound.", new TextFormat() { Font = StandardFonts.Times, FontSize = 11 }, rc); //Create an instance of SoundAnnotation class and set its relevant properties var aiffAnnot = new SoundAnnotation() { UserName = "Jaime Smith", Contents = "Sound annotation with an AIFF track.", PdfRect = new RectangleF(rc.Right, rc.Top, 24, 24), Icon = SoundAnnotationIcon.Speaker, Color = Color.Red, Sound = SoundObject.FromFile(Path.Combine("Resources", "Sounds", "ding.aiff"), AudioFormat.Aiff) }; page.Annotations.Add(aiffAnnot); doc.Save("SoundAnnotation.pdf"); } |
Widget annotations are used in interactive forms to represent the appearance of fields. It is also used to manage user interaction. DsPdf provides WidgetAnnotation class to to enable the users to apply widget annotations to the PDF file.
The following code illustrates how to add a widget annotation to a PDF document.
C# |
Copy Code
|
---|---|
public void CreateWidgetAnnotation() { var doc = new GcPdfDocument(); var page = doc.NewPage(); var g = page.Graphics; TextFormat tf = new TextFormat(); tf.FontSize = 11; PointF ip = new PointF(72, 72); float fldOffset = 72 * 2; float fldHeight = tf.FontSize * 1.2f; float dY = 32; // Text field: g.DrawString("Text field:", tf, ip); var fldText = new TextField(); fldText.Value = "Initial TextField value"; //Get the WidgetAnnotation to specify view properties of the text field. WidgetAnnotation widgetAnnotation = fldText.Widget; widgetAnnotation.Page = page; widgetAnnotation.PdfRect = new RectangleF(ip.X + fldOffset, ip.Y, 72 * 3, fldHeight); widgetAnnotation.Border.Color = Color.Silver; widgetAnnotation.BackColor = Color.LightSkyBlue; doc.AcroForm.Fields.Add(fldText); ip.Y += dY; doc.Save("WidgetAnnotation.pdf"); } |
A watermark annotation defines graphics that is expected to be printed at a fixed size and position on a page, regardless of the dimensions of the printed page. DsPdf provides WatermarkAnnotation class to enable the users to apply watermark annotations to the PDF file.
The following code illustrates how to add a watermark annotation to a PDF document.
C# |
Copy Code
|
---|---|
public void CreateWatermarkAnnotation() { GcPdfDocument doc = new GcPdfDocument(); var fs = new FileStream(Path.Combine("CompleteJavaScriptBook.pdf"), FileMode.Open, FileAccess.Read); doc.Load(fs); //Load the document //Loop over pages, add a watermark to each page: foreach (var page in doc.Pages) { //Create an instance of WatermarkAnnotation class and set its relevant properties var watermark = new WatermarkAnnotation() { PdfRect = new RectangleF(50, 300, 500, 150), Image = Image.FromFile("draft-copy.png"), Page = page // Add watermark to page }; doc.Save("WatermarkAnnotation.pdf"); } } |
Redact annotation removes the content from a PDF document that is not supposed to be shared. It can be applied in two phases:
When you mark the redact area, a marking or highlight appears in the place of content to show that the region has been marked for redaction. With DsPdf class library, you can find all instances of texts and mark the content for redaction. This allows anyone in charge for redaction to apply redactions on the marked content. DsPdf provides RedactAnnotation class to enable the users to mark redact area in the PDF file.
C# |
Copy Code
|
---|---|
public void CreatePDF() { GcPdfDocument doc = new GcPdfDocument(); var fs = new FileStream(Path.Combine("TimeSheet.pdf"), FileMode.Open, FileAccess.Read); doc.Load(fs); //Load the document //Create Redact annotation RedactAnnotation redactAnnotation = new RedactAnnotation(); //search the text(e.g employee name) which needs to be redacted var l = doc.FindText(new FindTextParams("Jaime Smith", true, false), null); // add the text's fragment area to the annotation List<Quadrilateral> area = new List<Quadrilateral>(); area.Add(l[0].Bounds[0]); redactAnnotation.Area = area; redactAnnotation.Justification = VariableTextJustification.Centered; redactAnnotation.MarkBorderColor = Color.Black; //Add the redact annotation to the page doc.Pages[0].Annotations.Add(redactAnnotation); doc.Save("TimeSheet_Redacted.pdf"); } |
Once the areas in a PDF document are marked for redaction, redaction can be applied to those areas to remove the content from PDF documents. After the PDF content is redacted, it cannot be extracted, copied or pasted in other documents. However, you can add overlay text in the place of redacted content.
DsPdf allows you to apply redact to areas marked for redaction in PDF documents by using the Redact method of GcPdfDocument class. The Redact method has three overloads which provides you with the option to apply redaction to all the areas marked for redaction, to a particular area marked for redaction or a list of areas marked for redaction in a PDF document.
The following code illustrates how to apply redaction in a PDF document.
C# |
Copy Code
|
---|---|
var doc = new GcPdfDocument(); using (var fs = new FileStream(Path.Combine("Resources", "PDFs", "TimeSheet_Redacted.pdf"), FileMode.Open, FileAccess.Read)) { // Load the PDF containing redact annotations (areas marked for redaction) doc.Load(fs); //mark new redact area var rc = new RectangleF(280, 150, 100, 30); var redact = new RedactAnnotation() { PdfRect = rc, Page = doc.Pages[0], OverlayFillColor = Color.PaleGoldenrod, OverlayText = "REDACTED", OverlayTextRepeat = true }; // Apply all redacts (above redact and existing area marked for redaction) doc.Redact(); doc.Save(stream); return doc.Pages.Count; } |
Text markup annotations is the simplest type of markup annotation for marking up page text. Text markup annotation appears as underlines, highlights, strikeouts or jagged underlines in the document's text. DsPdf provides TextMarkupAnnotation class to enable the users to apply text markup annotations to the PDF file.
The following code illustrates how to add a text markup annotation to a PDF document.
C# |
Copy Code
|
---|---|
public void CreateTextMarkupAnnotation() { GcPdfDocument doc = new GcPdfDocument(); var page = doc.NewPage(); var tl = page.Graphics.CreateTextLayout(); tl.DefaultFormat.Font = StandardFonts.Times; tl.DefaultFormat.FontSize = 14; tl.Append("This sample demonstrates how you can create Text markup annotation."); page.Graphics.DrawTextLayout(tl, new PointF(72, 72)); //Create an instance of TextMarkupAnnotation class and set its relevant properties var textMarkupAnnot = new TextMarkupAnnotation(); textMarkupAnnot.MarkupType = TextMarkupType.Highlight; textMarkupAnnot.UserName = "Jaime Smith"; textMarkupAnnot.Contents = "This is a Text markup annotation"; //search the text(e.g employee name) which needs to be redacted var found = doc.FindText(new FindTextParams("Text markup", true, false), null); List<Quadrilateral> area = new List<Quadrilateral>(); foreach (var f in found) area.Add(f.Bounds[0]); textMarkupAnnot.Area = area; textMarkupAnnot.Color = Color.Yellow; page.Annotations.Add(textMarkupAnnot); //Add the text markup annotation to the page doc.Save("TextMarkupAnnotation.pdf"); } |
Polyline annotations display closed or open shapes of multiple edges on the page. When clicked, it displays a pop-up window containing the text of the associated note. DsPdf provides PolyLineAnnotation class to enable the users to apply polyline annotations to the PDF file.
The following code illustrates how to add a polyline annotation to a PDF document.
C# |
Copy Code
|
---|---|
public void CreatePolyLineAnnotation() { GcPdfDocument doc = new GcPdfDocument(); Page page = doc.NewPage(); RectangleF rc = new RectangleF(50, 50, 400, 40); page.Graphics.DrawString("This sample demonstrates how you can create a polyline annotation.", new TextFormat() { Font = StandardFonts.Times, FontSize = 14 }, rc); //define the points of the polyline var points = new List<PointF>(); float x = rc.Left,y=rc.Bottom; for (int i=0 ;i<10 ;i++,x+=10) { points.Add(new PointF(x,y)); y = i % 2 == 0 ? y - 10 : y+10; } //Create an instance of PolyLineAnnotation class and set its relevant properties var polyLineAnnot = new PolyLineAnnotation() { Points = points, UserName = "Jaime Smith", LineWidth = 2, Color = Color.Green, Contents = "This is a polyline annotation", }; page.Annotations.Add(polyLineAnnot); //Add the polyline annotation to the page doc.Save("PolyLineAnnotation.pdf"); } |
Caret annotation is a visual symbol typically used to mark text for some changes or to indicate some missing text. DsPdf provides CaretAnnotation class that allows a user to add Caret annotations to the PDF file.
Refer to the following example code to add a caret annotation to a PDF document:
C# |
Copy Code
|
---|---|
// Initialize GcPdfDocument. GcPdfDocument doc = new GcPdfDocument(); // Create a file stream. FileStream fs = new FileStream("Wetlands.pdf", FileMode.Open, FileAccess.Read); // Load the file stream. doc.Load(fs); // Get the first page. var page = doc.Pages[0]; // Get the text map. var tm = page.GetTextMap(); // Insert the CaretAnnotation after "The Importance" text. tm.FindText(new FindTextParams("The Importance", false, true), (fp_) => { // r is bounds of the found text. var r = fp_.Bounds[0].ToRect(); // Create the CaretAnnotation and add it to the page. CaretAnnotation ca = new CaretAnnotation(); ca.Page = page; // in this code annotation size is hardcoded, you can make a code // which will adjust size of the annotation depending on height of the found text fragment ca.Rect = new System.Drawing.RectangleF(r.Right - 4, r.Bottom - 8, 8, 8); ca.Opacity = 1f; ca.Color = Color.Red; ca.Contents = "This is Caret annotation."; }); doc.Save("CaretAnnotation.pdf"); |
For more information about how to work with annotations using DsPdf, see DsPdf sample browser.