'''' This code is part of Document Solutions for PDF .NET demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.IOImportsSystem.DrawingImportsSystem.LinqImportsSystem.Collections.GenericImportsGrapeCity.Documents.PdfImportsGrapeCity.Documents.Pdf.AnnotationsImportsGrapeCity.Documents.Pdf.Actions '' This sample shows how to find and remove all links to a certain URL from a PDF.'' The code first finds all link annotations with ActionURI pointing to the URL'' that needs to be removed, then uses redact to erase all content within the found link areas.'' Red overlay is used by the redacts to visualize the erased areas.'''' The PDF used by this sample, but with links intact, can be seen in the FindAndHighlight sample.PublicClassRedactLinksPublicFunctionCreatePDF(ByVal stream AsStream) AsInteger'' Load the PDF with links that need to be removed:Dim doc = NewGcPdfDocument()Using fs = File.OpenRead(Path.Combine("Resources", "PDFs", "fendo-13-1005722.pdf")) doc.Load(fs) '' Remove all links containing this string:ConsttargetUrl = "frontiersin.org" '' Find all relevant link annotations:Dim linkAnnotations = NewHashSet(OfLinkAnnotation)()ForEach page In doc.PagesForEach a In page.AnnotationsIfTypeOf a IsLinkAnnotationThenDim la = DirectCast(a, LinkAnnotation)IfTypeOf la.ActionIsActionURIThenDim actUri = DirectCast(la.Action, ActionURI)IfNotString.IsNullOrEmpty(actUri.URI) AndAlso actUri.URI.Contains(targetUrl) Then linkAnnotations.Add(la)EndIfEndIfEndIfNextNext'' Loop through the found links, add redact annotations for each:ForEach la In linkAnnotationsForEach page In la.Pages' We must make a copy of page.Annotations to be able to add redact annotations in a foreach loop:Dim annots = page.Annotations.Where(Function(a_) a_ Is la).ToList()ForEach a In annots page.Annotations.Add(NewRedactAnnotation() With { .Rect = la.Rect, .OverlayFillColor = Color.Red })NextNextNext'' Apply the redacts: doc.Redact() '' Done: doc.Save(stream)Return doc.Pages.CountEndUsingEndFunctionEndClass