Examples for failing documents
Lines 269 to 279 in 96bd89f
# Possibly failing images redaction for get images counts mismatch
'failing images redaction (#165)': [
'samples_artifex/Bug6901014_CImg_flyer.pdf',
'samples_artifex/Bug6901014_launch_leaflet.pdf',
'samples_artifex/Transparency-DesignGuide.pdf',
'samples_artifex/torture.pdf',
'samples_pymupdf/test_2635.pdf',
'samples_pymupdf/test-3820.pdf',
'samples_pymupdf/test_3950.pdf',
'samples_pymupdf/test_open2.pdf',
],
- samples_artifex/torture.pdf
- with embedded vector images, not detected as drawings
- samples_artifex/Bug6901014_launch_leaflet.pdf
- with embedded vector images, and with clips, see #134
- samples_artifex/Transparency-DesignGuide.pdf
- ...
How to reproduce with PyMuPDF
document = pymupdf.Document("torture.pdf")
page = document[0]
page.add_redact_annot(page.rect, fill=False)
page.apply_redactions(images=pymupdf.PDF_REDACT_IMAGE_REMOVE)
document.save("torture-redacted.pdf", garbage=1)
The created torture-redacted.pdf contains indeed the same 4 images or drawings as the unredacted torture.pdf.
Inconsistently, page.get_images() and page.get_drawings() return no items, but page.get_image_info() returns 4 "images".
Upstream issues
Impact
(削除) Rather high, because user is not even warned because partial image redaction is used. (削除ここまで)
Edit: Likely not that high with !159, because on images count mismatch the user gets at least warned for possibly unredacted images (starting from v0.6.0):
Lines 431 to 452 in 96bd89f
# Check that number of images from different methods matches,
# see https://codeberg.org/censor/Censor/issues/165
if images != pymupdf.PDF_REDACT_IMAGE_NONE:
try:
n_images_get = len(mupdf_page.get_images())
n_images_info = len(mupdf_page.get_image_info())
n_images_blocks = sum(b[-1] == 1 for b in mupdf_page.get_text(
'blocks', flags=pymupdf.TEXT_PRESERVE_IMAGES,
clip=pymupdf.Rect(
pymupdf.FZ_MIN_INF_RECT, pymupdf.FZ_MIN_INF_RECT,
pymupdf.FZ_MAX_INF_RECT, pymupdf.FZ_MAX_INF_RECT)))
if not (n_images_get == n_images_info == n_images_blocks):
print(f'WARNING: Found {n_images_get} image(s) with '
+ f"'pymupdf.Page.get_images()', {n_images_info} image(s)"
+ " with 'pymupdf.Page.get_image_info()' and "
+ f'{n_images_blocks} image(s) with '
+ "'pymupdf.Page.get_text(\"blocks\", "
+ "flags=pymupdf.TEXT_PRESERVE_IMAGES)'")
warnings.append(_(
'Found possibly unredacted images during '
+ 'post-processing on page\xa0{number}'
).format(number=mupdf_page.number + 1))
## Examples for failing documents
https://codeberg.org/censor/Censor/src/commit/96bd89f19a24bb2b9d6c8ec89e6546fd730f271f/tests/document_test.py#L269-279
- [samples_artifex/torture.pdf](https://github.com/ArtifexSoftware/tests/blob/master/pdf/torture.pdf)
- with embedded vector images, not detected as drawings
- [samples_artifex/Bug6901014_launch_leaflet.pdf](https://github.com/ArtifexSoftware/tests/blob/master/pdf/Bug6901014_launch_leaflet.pdf)
- with embedded vector images, and with clips, see #134
- [samples_artifex/Transparency-DesignGuide.pdf](https://github.com/ArtifexSoftware/tests/blob/master/pdf/Transparency-DesignGuide.pdf)
- ...
## How to reproduce with PyMuPDF
```py
document = pymupdf.Document("torture.pdf")
page = document[0]
page.add_redact_annot(page.rect, fill=False)
page.apply_redactions(images=pymupdf.PDF_REDACT_IMAGE_REMOVE)
document.save("torture-redacted.pdf", garbage=1)
```
The created `torture-redacted.pdf` contains indeed the same 4 images or drawings as the unredacted `torture.pdf`.
Inconsistently, `page.get_images()` and `page.get_drawings()` return no items, but `page.get_image_info()` returns 4 "images".
## Upstream issues
-
## Impact
~Rather high, because user is not even warned because partial image redaction is used.~
Edit: Likely not that high with !159, because on images count mismatch the user gets at least warned for possibly unredacted images (starting from v0.6.0): https://codeberg.org/censor/Censor/src/commit/96bd89f19a24bb2b9d6c8ec89e6546fd730f271f/src/pymupdf_helpers.py#L431-452