Select specific pages for rasterized PDF

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 →

On this page

Saving document as a rasterized PDF, you can specify starting page index (zero based) and the number of pages from this index to save. Also, you can change the Compliance level from PDF/A-1b, which is used by default, to PDF/A-1a:

from groupdocs.redaction import Redactor, RedactionStatus
from groupdocs.redaction.options import SaveOptions, PdfComplianceLevel
from groupdocs.redaction.redactions import ExactPhraseRedaction, ReplacementOptions
from groupdocs.redaction.options.drawing import Color


def select_specific_pages_for_rasterized_pdf():
    # Define the color of redaction
    color = Color.from_argb(255, 220, 20, 60)

    # Specify the redaction options
    repl_opt = ReplacementOptions(color)
    ex_red = ExactPhraseRedaction("Emily Johnson", repl_opt)

    # Load the document to be redacted
    with Redactor("./multipage_sample.docx") as redactor:

        # Apply the redaction
        result = redactor.apply(ex_red)

        if result.status != RedactionStatus.FAILED:
            # Save the processed document, selecting the page range and compliance level
            so = SaveOptions()
            so.rasterization.enabled = True  # convert pages to images for compatibility
            so.rasterization.page_index = 2  # start from the 3rd page (index is 0-based)
            so.rasterization.page_count = 1  # save only one page
            so.rasterization.compliance = PdfComplianceLevel.PDF_A1A  # PDF/A-1a format
            so.add_suffix = False
            result_path = redactor.save(so)

            print(f"Document redacted successfully.\nCheck output in {result_path}")
        else:
            print("Redaction failed!")


if __name__ == "__main__":
    select_specific_pages_for_rasterized_pdf()

multipage_sample.docx is the sample file used in this example. Click here to download it.

Binary file (PDF, 2.5 MB)

Download full output

On this page