PyMuPDF icon indicating copy to clipboard operation
PyMuPDF copied to clipboard

page.apply_redactions() breaks transparent images in pdf

Open koopmac opened this issue 5 years ago • 6 comments

Please provide all mandatory information!

Describe the bug (mandatory)

When using page.apply_redactions() on a pdf with an image that was originally transparent, the image background turns an odd black colour.

To Reproduce (mandatory)

doc = fitz.open(<path/to/pdf_with_transparent_img>) for page in doc: ... redaction = page.addRedactAnnot(new_area, fill=col, text=" ") ... page.apply_redactions()

Expected behavior (optional)

background for images should remain white (transparent)

Screenshots (optional)

image

Your configuration (mandatory)

  • Python==3.8.2
  • PyMuPDF==1.18.8

koopmac avatar Feb 15 '21 04:02 koopmac

This a known problem. It can be circumvented by either

  • removing the complete overlapping image, page.apply_redations(images=fitz.PDF_REDACT_IMAGE_REMOVE), or
  • ignoring the image overlap page.apply_redations(images=fitz.PDF_REDACT_IMAGE_NONE)

JorjMcKie avatar Feb 15 '21 08:02 JorjMcKie

Issue resolved with circumvention?

JorjMcKie avatar Feb 18 '21 11:02 JorjMcKie

@JorjMcKie I am also facing the same issue. are there any other alternatives other than the mentioned one?

MallRoy avatar Aug 17 '21 09:08 MallRoy

alternatives other than the mentioned one?

No. You may want to consider covering the resp. image part with the redaction rectangle having a background color (e.g. white) instead.

JorjMcKie avatar Aug 17 '21 09:08 JorjMcKie

Ok. will try that. is there any way to identify images in a PDF

MallRoy avatar Aug 17 '21 10:08 MallRoy

any way to identify images in a PDF

What does that mean? There are more than one method for this: doc.get_page_images(), page.get_image_info(), page.get_text(), furthermore methods for locating image positions on the page, transformation matrices that made the original image fit into their bbox, etc., etc.

JorjMcKie avatar Aug 17 '21 10:08 JorjMcKie