'''' This code is part of Document Solutions for PDF .NET demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.IOImportsSystem.DrawingImportsGrapeCity.Documents.PdfImportsGrapeCity.Documents.Pdf.AnnotationsImportsGrapeCity.Documents.Text '' Shows how to add annotations to a PDF document.PublicClassAnnotationTypesFunctionCreatePDF(ByVal stream AsStream) AsIntegerDim doc = NewGcPdfDocument()Dim page = doc.NewPage()'' User names for annotations' authors:Dim user1 = "Jaime Smith"Dim user2 = "Jane Donahue" Dim tf = NewTextFormat() With {.Font = StandardFonts.Helvetica, .FontSize = 10}Dim noteWidth = 72 * 4Dim gap = 8 Dim rc = Util.AddNote("This sample demonstrates some types of annotations that can be created with DsPdf." + vbLf +"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:Dim ip = NewPointF(rc.X, rc.Bottom + gap) rc = Util.AddNote("A red text annotation is placed to the right of this note.", page, NewRectangleF(ip.X, ip.Y, noteWidth, 100))Dim textAnnot = NewTextAnnotation() With { .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:Dim textAnnotReply = NewTextAnnotation() With { .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 = 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))Dim textAnnotOpen = NewTextAnnotation() With { .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 = 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))Dim freeAnnot = NewFreeTextAnnotation() With { .Rect = NewRectangleF(rc.Right + 18, rc.Bottom + 9, 72 * 2, 72), .CalloutLine = {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 = NewSingle() {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)Dim freeRichAnnot = NewFreeTextAnnotation() With { .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 = 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)Dim squareAnnot = NewSquareAnnotation() With { .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.CountEndFunctionEndClass