Skip to content

Inconsistent defaults in documentation and source for pymudpf.Page.apply_redactions #4924

@mahlzahn

Description

@mahlzahn

Description of the bug

Documentation

apply_redactions(images=PDF_REDACT_IMAGE_PIXELS|2,
                 graphics=PDF_REDACT_LINE_ART_REMOVE_IF_TOUCHED|2,
                 text=PDF_REDACT_TEXT_REMOVE|0)
  • int graphics: How to redact overlapping vector graphics (also called "line-art" or "drawings"). The default (2) removes any overlapping vector graphics. PDF_REDACT_LINE_ART_NONE | 0 ignores, and PDF_REDACT_LINE_ART_REMOVE_IF_COVERED | 1 removes graphics fully contained in a redaction annotation.

PyMuPDF/docs/page.rst

Lines 335 to 343 in 4bfc665

.. method:: apply_redactions(images=PDF_REDACT_IMAGE_PIXELS|2, graphics=PDF_REDACT_LINE_ART_REMOVE_IF_TOUCHED|2, text=PDF_REDACT_TEXT_REMOVE|0)
**PDF only**: Remove all **content** contained in any redaction rectangle on the page.
**This method applies and then deletes all redactions from the page.**
:arg int images: How to redact overlapping images. The default (2) blanks out overlapping pixels. `PDF_REDACT_IMAGE_NONE | 0` ignores, and `PDF_REDACT_IMAGE_REMOVE | 1` completely removes images overlapping any redaction annotation. Option `PDF_REDACT_IMAGE_REMOVE_UNLESS_INVISIBLE | 3` only removes images that are actually visible.
:arg int graphics: How to redact overlapping vector graphics (also called "line-art" or "drawings"). The default (2) removes any overlapping vector graphics. `PDF_REDACT_LINE_ART_NONE | 0` ignores, and `PDF_REDACT_LINE_ART_REMOVE_IF_COVERED | 1` removes graphics fully contained in a redaction annotation. When removing line-art, please be aware that **stroked** vector graphics (i.e. type "s" or "sf") have a **larger wrapping rectangle** than one might expect: first of all, at least 50% of the path's line width have to be added in each direction to truly include all of the drawing. If a so-called "miter limit" is provided (see page 121 of the PDF specification), the enlarging value is `miter * width / 2`. So, when letting everything default (width = 1, miter = 10), the redaction rectangle should be at least 5 points larger in every direction.

Source code (actual behaviour)

PyMuPDF/src/__init__.py

Lines 10659 to 10681 in 4bfc665

def apply_redactions(
page: 'Page',
images: int = 2,
graphics: int = 1,
text: int = 0,
) -> bool:
"""Apply the redaction annotations of the page.
Args:
page: the PDF page.
images:
0 - ignore images
1 - remove all overlapping images
2 - blank out overlapping image parts
3 - remove image unless invisible
graphics:
0 - ignore graphics
1 - remove graphics if contained in rectangle
2 - remove all overlapping graphics
text:
0 - remove text
1 - ignore text
"""

How to solve?

Either update the documentation (simpler) or the default in source code (breaking change, but more secure saving redaction option).

How to reproduce the bug

use the function

PyMuPDF version

1.27.2

Operating system

Linux

Python version

3.14

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions