Redact PDF via C++

PDF document sensitive redaction information. Use Aspose.PDF for C++ to modify PDF documents programmatically

How to Redact PDF File Using C++ Library

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

Redact PDF documents via C++


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

  1. Load the PDF with an instance of Document.
  2. Create TextFragmentAbsorber object with search terms as argument.
  3. Set Search Options.
  4. Loop through each fragment collect to redact.
  5. Save PDF file.

Redact PDF Files - C++


    // Load PDF file
    auto pdfDocument = MakeObject<Document>(u"sourceFile.pdf");

    // Create TextAbsorber object to find all instances of the input search phrase
    auto textFragmentAbsorber = MakeObject<TextFragmentAbsorber>(u"Document");

    // Accept the absorber for all the pages
    pdfDocument->get_Pages()->Accept(textFragmentAbsorber);

    // Get the extracted text fragments
    auto textFragmentCollection = textFragmentAbsorber->get_TextFragments();

    // Loop through the fragments
    for (auto textFragment : textFragmentCollection){
        // Update text and other properties
        textFragment->set_Text(u"UPDATED TEXT");
        textFragment->get_TextState()->set_Font(FontRepository::FindFont(u"TimesNewRoman"));
        textFragment->get_TextState()->set_FontSize(22);
    }

    // Save the resulting PDF document.
    pdfDocument->Save(u"outputFile.pdf");