//// This code is part of Document Solutions for PDF .NET demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem.IO;usingSystem.Drawing;usingGrapeCity.Documents.Pdf;usingGrapeCity.Documents.Pdf.Annotations; namespaceDsPdfWeb.Demos.Basics{// Shows how to add annotations to a PDF document.publicclassAnnotationTypes {publicintCreatePDF(Stream stream) {var doc = newGcPdfDocument();var page = doc.NewPage();var g = page.Graphics;// User names for annotations' authors:var user1 = "Jaime Smith";var user2 = "Jane Donahue"; var noteWidth = 72 * 4;var gap = 8; var rc = Common.Util.AddNote("This sample demonstrates some types of annotations that can be created with DsPdf.\n" +"Note that some annotation types may not display in certain viewers (such as built-in browser viewers)." +"To see all annotations on this page, open it in Acrobat Reader or other full-featured PDF viewer.", page); // Text annotation:var ip = newPointF(rc.X, rc.Bottom + gap); rc = Common.Util.AddNote("A red text annotation is placed to the right of this note.", page, newRectangleF(ip.X, ip.Y, noteWidth, 100));var textAnnot = newTextAnnotation() {UserName = user1,Contents = "This is annotation 1, a red one.",Rect = newRectangleF(rc.Right, rc.Top, 72 * 2, 72),Color = Color.Red, }; page.Annotations.Add(textAnnot);// A reply to previous annotation:var textAnnotReply = newTextAnnotation() {UserName = user2,Contents = "This is a reply to the first annotation.",Rect = newRectangleF(rc.Right, rc.Top, 72 * 2, 72),ReferenceAnnotation = textAnnot,ReferenceType = AnnotationReferenceType.Reply, }; page.Annotations.Add(textAnnotReply); // An initially open text annotation: ip = newPointF(rc.X, rc.Bottom + gap); rc = Common.Util.AddNote("A green text annotation that is initially open is placed to the right of this note.", page, newRectangleF(ip.X, ip.Y, noteWidth, 100));var textAnnotOpen = newTextAnnotation() {Open = true,UserName = user1,Contents = "This is an initially open annotation (green).",Rect = newRectangleF(rc.Right, rc.Top, 72 * 2, 72),Color = Color.Green, }; page.Annotations.Add(textAnnotOpen); // A free text annotation (shows directly on page): ip = newPointF(rc.X, rc.Bottom + gap); rc = Common.Util.AddNote("A blue free text annotation is placed below and to the right, with a callout going from it to this note.", page, newRectangleF(ip.X, ip.Y, noteWidth, 100));var freeAnnot = newFreeTextAnnotation() {Rect = newRectangleF(rc.Right + 18, rc.Bottom + 9, 72 * 2, 72),CalloutLine = newPointF[] {newPointF(rc.Left + rc.Width / 2, rc.Bottom),newPointF(rc.Left + rc.Width / 2, rc.Bottom + 9 + 36),newPointF(rc.Right + 18, rc.Bottom + 9 + 36), },LineWidth = 1,LineEndStyle = LineEndingStyle.OpenArrow,LineDashPattern = newfloat[] { 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); // Another free text annotation, with some rich text inside: ip = newPointF(rc.X, freeAnnot.Rect.Bottom + gap);var freeRichAnnot = newFreeTextAnnotation() {Rect = newRectangleF(ip.X - 144, ip.Y, 72 * 5, 72),LineWidth = 1,Color = Color.LightSalmon,RichText ="<body><p>This is another <i>free text annotation</i>, with <b><i>Rich Text</i></b> content.</p>" +"<p>Even though a <b>free text</b> annotation displays text directly on a page, " +"as other annotations it can be placed outside the page's bounds.</p></body>" }; page.Annotations.Add(freeRichAnnot); // A square annotation around a note: ip = newPointF(rc.X, freeRichAnnot.Rect.Bottom + gap * 2); rc = Common.Util.AddNote("A square annotation drawn with a 3pt wide orange line around this note has a rich text associated with it.", page, newRectangleF(ip.X, ip.Y, noteWidth, 100)); rc.Inflate(8, 8);var squareAnnot = newSquareAnnotation() {UserName = user2,Rect = 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); // Done: doc.Save(stream);return doc.Pages.Count; } }}