'''' 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.Svg '' Shows how to programmatically control which annotations to include when saving a PDF as images.'' The sample loads a one-page PDF containing several annotations, and saves that page as SVG'' using DrawAnnotationFilter to include only annotations which satisfy certain conditions'' (free text annotations that are within the page bounds).'' The SVG is then inserted as the first page of the resulting PDF.'' The second page shows the original PDF for reference.PublicClassAnnotationDrawFilterPublicFunctionCreatePDF(ByVal stream AsStream) AsIntegerDim doc = NewGcPdfDocument()' Load a PDF with some annotations into the document:Using fs = File.OpenRead(Path.Combine("Resources", "PDFs", "AnnotationTypes.pdf")) doc.Load(fs)Using svgStream = NewMemoryStream()' Draw the first page of the PDF into an SVG: doc.Pages(0).SaveAsSvg(svgStream,NewSaveAsImageOptions() With { .BackColor = Color.Transparent, .DrawAnnotationFilter = AddressOfFilterAnnotations }) svgStream.Position = 0' Create a GcSvgDocument from the saved SVG so that we can draw it in the resulting PDF:Using svgDoc = GcSvgDocument.FromStream(svgStream)' Insert a page into the PDF and draw the SVG on it, compare to the original on the 2nd page:Dim page = doc.Pages.Insert(0)Dim g = page.GraphicsDim rc = NewRectangleF(36, 36, page.Size.Width - 72, page.Size.Height - 72) g.DrawRectangle(rc, Color.DarkGoldenrod) g.FillRectangle(rc, Color.PaleGoldenrod) g.DrawSvg(svgDoc, rc)EndUsingEndUsing ' Done: doc.Save(stream)EndUsingReturn doc.Pages.CountEndFunction PrivateSubFilterAnnotations(ByVal d AsGcPdfDocument, ByVal p AsPage, ByVal a AsAnnotationBase, ByRef draw AsBoolean)' Draw only free text annotations which also fit horizontally within the page bounds:IfTypeOf a IsFreeTextAnnotationThenDim fta = DirectCast(a, FreeTextAnnotation) draw = fta.Rect.Left > 0AndAlso fta.Rect.Right < p.Size.WidthElse draw = FalseEndIfEndSubEndClass