Redacting photos and scans inside a PDF
· 6 min read
A black box drawn over a photograph is a shape sitting on top of an intact picture. Redacting an image means changing its pixels and re-encoding it, so the original picture is no longer in the file at all. Preview’s Redact tool does that by area, and the parts people miss are the invisible text layer under a scan, the edge of the mark, and the same image appearing somewhere else in the document.
This post covers the image case specifically, because it fails differently from text and the checks are different too.
Why an image is not like text
Page text is a list of instructions: place this glyph here, in this font, at this size. A redaction can remove individual glyphs from that list and write the survivors back, which is why a properly redacted paragraph still reads around the gap.
An image is one object. The whole photograph or the whole scanned page is a single compressed stream, drawn onto the page at a position and a size. There is no way to remove part of it in the way you remove a word. The only honest operation is to decode the picture, alter the pixels in the region you marked, re-encode it, and replace the object.
Anything that skips that step leaves the original stream sitting in the file, complete, and anything that extracts images from PDFs gets it back.
Doing it in Preview
Preview has had a real Redact tool since macOS 11, and it works on areas as well as on text.
- Open the PDF and choose File, Duplicate (Shift-Command-S). Work on the copy; Preview saves edits into the file you have open, and redaction is meant to be irreversible.
- Tools, Redact. Accept the warning that content will be permanently removed on save.
- Drag a rectangle over the region of the photograph or the scan.
- Repeat across the document, then File, Save.
- Close the window, reopen the saved file, and look at it again. From here on, only the saved file counts.
Preview alters the pixels in the marked region, so the picture data for that area is not preserved in the file. Redacting a PDF in Preview covers the tool in general and where it stops short.
The invisible text layer under a scan
A scan that has been made searchable has two things on the page: the image you can see, and a layer of invisible text positioned over it so that search and copy work. That layer contains the words.
So a scanned page can fail in two directions at once. The pixels can be gone while the OCR text is still there, or the text can be removed while the picture underneath is intact. Test both after you save:
- Command-A, Command-C in Preview, paste into TextEdit, and search for the words you removed.
- Run the file through Automator’s Extract PDF Text action, which pulls text the copy command can miss, and search that too.
- Zoom to maximum on the marked area and look at the pixels.
If you have not run OCR yet, consider the order. Redacting first and making the document searchable afterwards means the text layer is generated from a page that no longer contains the sensitive content. Make a scanned PDF searchable on a Mac covers the OCR side.
Edges, fringes and second copies
Zoom in before you decide the mark is good enough.
Cover the whole character, not most of it. Descenders, accents and the tails of handwriting sit outside the rough box your eye draws at normal zoom. A digit that is half visible is often enough to guess.
Expect rounding at the edge. A mark drawn on screen maps onto image pixels, and at a scan resolution of several hundred dots per inch, a one pixel discrepancy at the boundary is a real row of the original image. Draw the mark generously.
Look for the same picture elsewhere. A photograph used on an exhibit cover and again in the body is two draws of one image object, or two objects with the same content. Marking one page does not touch the other. Search the document visually, page by page, before you decide you are done.
Remember the container. Embedded page thumbnails, attachments and hidden layers can hold the picture as it was. What a PDF still hides goes through those.
Blur and pixelation are not redaction
Two reasons, and they are independent.
The first is that the information is still in the picture. A mosaic over a six digit number is a puzzle with a small answer space, and a blur is a mathematical transformation of the original values, not a removal of them. Solid fill is the only mark that carries no information about what it covers.
The second is worse: many blur and pixelate effects are applied as something drawn on top rather than baked into the image object. In that case the original picture is still in the file underneath the effect, exactly as it would be under a black rectangle.
If you want the reader to see that something was removed, use a solid mark. A redacted document with no visible marks is one nobody can check.
Checking the output
Beyond the text checks above, two things worth doing for image redactions in particular.
Compare the file sizes. In Terminal, ls -l on the original and the redacted copy. If a photograph was decoded, altered and re-encoded, the byte count almost always changes. A redacted file that is identical in size to the original is a file where nothing was rewritten, which is a strong hint that the mark is an annotation.
Open it somewhere else. Quick Look from Finder (select the file, press Space), a browser, a phone. Viewers differ in how they draw annotations, and one that ignores them shows the page as it really is.
How to check whether a PDF was really redacted is the full routine, and it is worth running on every file you are about to send rather than on the one you were working in.
If the checking needs to be part of the export rather than a habit, Basalt destroys and re-encodes the image under every mark, then re-opens the finished file with an independent parser and proves the pixels changed and the removed strings are absent before any file is written. If a check fails, nothing is written at all.
Questions
Can I just crop the photograph out of the page? Cropping in Preview changes which part of the page is displayed. The content outside the crop is generally still in the file and other software can be told to show it, so treat cropping as hiding rather than removing.
Is a screenshot of each page a safe redaction? It removes the underlying data for the pages you screenshot, at the cost of every page becoming an image with no searchable text and a much larger file. It also does nothing about metadata, attachments or bookmarks, which survive the process untouched.
The scan is a bad photocopy. Do I still need to worry about a text layer? Check rather than assume. If the Automator extraction returns nothing for those pages, there is no layer. If it returns garbled text, there is a layer and it needs the same treatment as clean text.
Does redacting an image change the rest of the page? The image object is rewritten, so the file changes, but the layout and any text on the page stay as they were. If the whole page is one scan, the entire page image is re-encoded even though only a small region looks different.