RedactArea.cs
  1. //
  2. // This code is part of Document Solutions for PDF demos.
  3. // Copyright (c) MESCIUS inc. All rights reserved.
  4. //
  5. using System.IO;
  6. using System.Drawing;
  7. using System.Text.RegularExpressions;
  8. using GrapeCity.Documents.Pdf;
  9. using GrapeCity.Documents.Pdf.Annotations;
  10. using GrapeCity.Documents.Pdf.TextMap;
  11. using GrapeCity.Documents.Pdf.AcroForms;
  12.  
  13. namespace DsPdfWeb.Demos
  14. {
  15. // This sample demonstrates the use of GcPdfDocument.Redact() method.
  16. // It loads the PDF generated by the SlidePages sample, creates
  17. // a redact annotation on the first page, and applies it.
  18. public class RedactArea
  19. {
  20. public int CreatePDF(Stream stream)
  21. {
  22. var doc = new GcPdfDocument();
  23. using var fs = File.OpenRead(Path.Combine("Resources", "PDFs", "SlidePages.pdf"));
  24. // Load the PDF containing redact annotations (areas marked for redaction):
  25. doc.Load(fs);
  26.  
  27. var redact = new RedactAnnotation()
  28. {
  29. Rect = new RectangleF(16, 16, 280, 300),
  30. Page = doc.Pages[0],
  31. OverlayText = "This content has been redacted.",
  32. OverlayFillColor = Color.PaleGoldenrod
  33. };
  34.  
  35. // Apply the redact:
  36. doc.Redact(redact);
  37.  
  38. // Done:
  39. doc.Save(stream);
  40. return doc.Pages.Count;
  41. }
  42. }
  43. }
  44.