Create PDF with Image Redaction

View as MarkdownMarkdown

Set up your AI agent

Give your coding agent live access to the GroupDocs documentation and API reference through the GroupDocs Docs MCP server — no install, no API key. Learn more

claude mcp add --transport http groupdocs-docs https://docs.groupdocs.com/mcp

Also process documents locally

The GroupDocs.Redaction MCP server lets your agent work with files on your machine; they are never uploaded. It needs the .NET 10 SDK or Docker.

claude mcp add groupdocs-redaction -- dnx GroupDocs.Redaction.Mcp --yes
Folders, licensing and more →

In some cases you might need to redact the pages of a document as images, redacting entire areas of the page instead or in addition to a specific text. With GroupDocs.Redaction you can use the following approach:

  • open the document and apply all required redactions to the document’s body (text, annotations, etc.);

  • save it as a rasterized PDF file (containing images of the original document’s pages);

  • apply ImageAreaRedaction to remove specific areas on the pages within the PDF document.

The following example demonstrates how to create a rasterized PDF from a Microsoft Word document and apply image redactions to its pages:

C#

using GroupDocs.Redaction.Options.Drawing;

var stream = new MemoryStream();
// Rasterize the document before applying redactions
using (var redactor = new Redactor("C:\\Temp\\sample.docx"))
{
    // Perform annotation and textual redactions, if needed
    redactor.Save(stream, new RasterizationOptions() { Enabled = true });
    stream.Seek(0, SeekOrigin.Begin);
}
// Re-open the rasterized PDF document to redact its pages as images
using (var redactor = new Redactor(stream))
{
    RedactorChangeLog result = redactor.Apply(new Redactions.ImageAreaRedaction(new Point(1160, 2375),
        new RegionReplacementOptions(Color.FromArgb(255, 0, 255, 255), new Size(1050, 720))));
    if (result.Status != RedactionStatus.Failed)
    {
        using (var fileStream = File.OpenWrite("C:\\Temp\\sample_docx_Raster.pdf"))
        {
            redactor.Save(fileStream, new RasterizationOptions() { Enabled = false });
        }
    }
}

Please, note that you don’t have to use GroupDocs.Redaction to create a rasterized PDF from an office document. You will be able to use it, if you don’t have any other tool for that.

More resources

GitHub examples

You may easily run the code above and see the feature in action in our GitHub examples:

Free online document redaction App

Along with full featured .NET library we provide simple, but powerful free Apps.

You are welcome to perform redactions for various document formats like PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX, Emails and more with our free online Free Online Document Redaction App.