Add Redaction Annotations in PDF using C++

Add Redaction annotation to PDF document programmaticaly using Aspose.PDF for C++ Library

In order to annotate PDF file, we’ll useAspose.PDF for C++ API which is a feature-rich, powerful and easy to use document manipulation API for C++ platform. Open NuGet package manager, search for Aspose.PDF and install. You may also use the following command from the Package Manager Console.

Package Manager Console

PM > Install-Package Aspose.PDF.Cpp

Add Redaction Annotation via C++


You need Aspose.PDF to try the code in your environment.

  • Load PDF in an instance of Document class
  • Create a new page or get a reference to an existing one
  • Create Redaction annotation
  • Call method Add for Redaction annotation from Page.Annotations collections
  • Save the file again

System Requirements


Aspose.PDF for C++ is supported on all major operating systems. Just make sure that you have the following prerequisites.

  • Microsoft Windows or a compatible OS with C++ Runtime Environment for Windows 32 bit, Windows 64 bit and Linux 64 bit.
  • Development environment like Microsoft Visual Studio.
  • Aspose.PDF for C++ DLL referenced in your project.

Add Redaction Annotations from PDF - C++

Example

    // Load the PDF file
    Document document = new Document(System.IO.Path.Combine(_dataDir, "sample.pdf"));
    // Create RedactionAnnotation instance for specific page region
    RedactionAnnotation annot = new RedactionAnnotation(doc.Pages[1], new Aspose.Pdf.Rectangle(200, 500, 300, 600));
    annot.FillColor = Aspose.Pdf.Color.Green;
    annot.BorderColor = Aspose.Pdf.Color.Yellow;
    annot.Color = Aspose.Pdf.Color.Blue;
    // Text to be printed on redact annotation
    annot.OverlayText = "REDACTED";
    annot.TextAlignment = Aspose.Pdf.HorizontalAlignment.Center;
    // Repat Overlay text over redact Annotation
    annot.Repeat = true;
    document.Pages[1].Annotations.Add(RedactionAnnotation1);
    document.Save(System.IO.Path.Combine(_dataDir, "sample_Redaction.pdf"));