//// This code is part of Document Solutions for PDF .NET demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem.IO;usingSystem.Drawing;usingSystem.Collections.Generic;usingGrapeCity.Documents.Pdf;usingGrapeCity.Documents.Pdf.Annotations;usingGrapeCity.Documents.Pdf.Actions;usingSystem.Linq; namespaceDsPdfWeb.Demos{// 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.publicclassRedactLinks {publicintCreatePDF(Stream stream) {// Load the PDF with links that need to be remove:var doc = newGcPdfDocument();usingvar fs = File.OpenRead(Path.Combine("Resources", "PDFs", "fendo-13-1005722.pdf")); doc.Load(fs); // Remove all links containing this string:conststringtargetUrl = "frontiersin.org"; // Find all relevant link annotations:var linkAnnotations = newHashSet<LinkAnnotation>();foreach (var page in doc.Pages) {foreach (var a in page.Annotations) {if (a isLinkAnnotation la && la.ActionisActionURI actUri) {if (!string.IsNullOrEmpty(actUri.URI) && actUri.URI.Contains(targetUrl)) { linkAnnotations.Add(la); } } } }// Loop through the found links, add redact annotations for each:foreach (var la in linkAnnotations) {foreach (var page in la.Pages) {// We must make a copy of page.Annotations to be able to add redact annotations in a foreach loop:var annots = page.Annotations.Where(a_ => a_ == la).ToList();foreach (var a in annots) { page.Annotations.Add(newRedactAnnotation() {Rect = la.Rect,OverlayFillColor = Color.Red }); } } }// Apply the redacts: doc.Redact(); // Done: doc.Save(stream);return doc.Pages.Count; } }}