PDF extraction
How to Redact Documents Securely: A Developer's Guide
How to redact documents so the data is actually gone: PII discovery, permanent removal, OCR and scanned files, metadata scrubbing, and an API workflow.
You have a PDF that needs to leave your system today. It might be a support export with emails and phone numbers, a legal attachment with personal details, or a scanned statement headed into OCR and search. The common move is fast and familiar: open the file, draw black boxes, export, send.
That works only if you define “works” as “looks hidden on screen.”
In practice, how to redact documents is a data-destruction problem, not a drawing problem. If the underlying text survives in the text layer, comments, tracked changes, attachments, metadata, or OCR output, the document is still carrying the thing you meant to remove. That’s why teams that care about privacy and release workflows treat redaction as part of records handling and release control, not as a last-minute PDF edit.
Table of Contents
- Beyond the Black Box Why Most Redaction Fails
- Choosing Your Redaction Method Manual vs Automated
- The Irreversible Redaction Workflow
- Sanitizing Hidden Data and Metadata
- Redacting Scanned Documents and OCR Text
- How to Verify Your Redaction Is Permanent
- Automating Redaction for Your Application with an API
Beyond the Black Box Why Most Redaction Fails
A document leaves your team looking clean in the viewer. An hour later, someone presses Ctrl+F, finds a Social Security number under the black bar, and exports the text. That is the failure mode to design against.
Digital redaction fails when teams treat appearance as proof of removal. A black rectangle can hide text on screen while the underlying characters, annotations, layers, revision history, or embedded objects remain intact in the file. Once that file enters OCR, indexing, eDiscovery, AI extraction, or a repository with weak document governance, the hidden content becomes easy to recover.

Fake redaction looks correct until someone tests it
A common redaction failure starts with one of these shortcuts:
- Drawing shapes over text leaves the source text in the page content stream.
- Changing font color to match the background keeps the text selectable and extractable.
- Using highlight or fill tools changes presentation only.
- Cropping the visible page area can hide content in the viewer while preserving the original page objects.
- Exporting a file after visual edits can keep comments, attachments, tracked changes, form values, or prior revisions.
These methods fail for a simple reason. They obscure. They do not sanitize.
The practical test is brutal and reliable. Open the file and try to search for the redacted term. Try to select text through the covered area. Try copy-paste. Inspect comments and attachments. Run text extraction with a PDF library. If any of that still works, the document was never safely redacted.
Practical rule: If software can still read it, your pipeline can still leak it.
Redaction is a file-sanitization problem
This gets missed in a lot of how-to guides. The deliverable is not a document that looks censored. The deliverable is a document whose sensitive content has been removed in a way that survives downstream processing.
That distinction matters in production systems. Search indexes read text layers. OCR recreates text from pixels. Conversion tools rewrite PDFs into HTML, DOCX, or JSON. LLM and RAG pipelines extract anything they can parse. A file that appears safe to a reviewer can still expose names, account numbers, or case details the moment another system touches it.
In practice, good redaction behaves like a release gate. The file should be safe to share externally, safe to store, and safe to process again without re-exposing the original content. That standard is higher than drawing a box, and it is the only standard that holds up once documents move through real applications.
Choosing Your Redaction Method Manual vs Automated
A team gets away with manual redaction right up until the first file slips through with searchable text still intact. That usually happens under normal conditions, not dramatic ones. A shared inbox fills up, someone covers text visually instead of removing it, the file gets indexed later, and the “redacted” data shows up in search, OCR output, or an LLM prompt.
The essential choice is not convenience versus sophistication. It is whether the method can produce a sanitized file reliably under the volume and variability you encounter.

Manual redaction is fine for exceptions
Manual tools still have a place. I use them for documents that need human judgment, especially when the target is contextual and pattern matching would over-redact or miss nuance.
Good manual candidates include:
| Use case | Why manual works |
|---|---|
| One-off legal or HR document | A reviewer can decide line by line what must stay or go |
| Mixed layouts and poor scans | Humans adapt better than rules when the input is ugly |
| Small release batches | Review time stays manageable |
| Final exception handling | Edge cases need a person, not another regex |
The trade-off is consistency. Manual redaction depends on reviewer attention, tool knowledge, and time. It breaks down fast when multiple people handle files differently or when one person has to process too many pages in a row.
It also creates a hidden QA problem. A reviewer may correctly mark content for removal but fail to apply the redaction in a way that destroys the underlying text layer. If you use a desktop workflow, make sure the final output is flattened and permanently applied before release. A simple PDF flattening step for the final export helps prevent annotation-style markup from surviving into downstream systems.
Automated redaction wins in repeatable pipelines
Automation makes sense when redaction is part of a system instead of a one-off desktop task. That includes upload flows, batch processing, eDiscovery pipelines, claim intake, support portals, and any product that sends documents into OCR, indexing, extraction, or AI features after upload.
For engineering teams, the dividing line is simple. If the file will be processed again, treat redaction as a deterministic sanitization step.
That gives you a few concrete advantages:
- Repeatability. The same rule runs on every document.
- Audit logs. The system can record what was matched, removed, and released.
- Throughput. Queues and batch jobs handle volume better than reviewers do.
- Safer downstream processing. Sanitization happens before other services extract text.
Speed matters, but predictability matters more. The goal is to make the safe output the default output.
A simple decision framework
Use manual redaction when all of the following are true:
- The file count is low
- A reviewer needs to interpret context
- The release set is small enough to inspect carefully
- The process does not depend on high-volume repeatability
Use automated redaction when any of these are true:
- Users upload documents continuously
- You remove recurring data like names, account numbers, addresses, or contact details
- The file will later be searched, parsed, classified, or sent to AI systems
- You need logs, consistency, and a release process that does not depend on operator memory
Many teams end up with a hybrid model. Automation handles the common path. Humans review low-confidence matches, unusual layouts, and policy exceptions.
That split works well in production because it respects the inherent trade-off. Humans are better at ambiguity. Systems are better at doing the same safe thing every time.
The Irreversible Redaction Workflow
A safe workflow has a boring property that matters a lot in production. Every step has one output, and that output is harder to reverse than the step before it.
A solid legal workflow preserves an original clean source copy, redacts only on a duplicate, permanently burns in each redaction, and then scrubs the text layer and metadata before release, as described in Logikcull’s guide to proper document redaction.

Start with the duplicate, not the source
Never redact the only copy.
Keep the original file untouched and create a working duplicate. That gives you three benefits: you preserve chain of custody, you can redo the job if the scope changes, and you avoid accidental loss of the source data.
A minimal release set should include:
- Original source file kept internal and access-controlled
- Working copy used for markup, OCR, and redaction
- Final release copy that has been burned in, sanitized, and verified
For teams doing this often, naming and storage discipline matter more than people expect. If reviewers can’t tell which file is the releasable one, someone will eventually send the wrong version.
Redact what users see and what software sees
Visible content comes first. That includes text, tables, images, signatures, handwritten notes, and embedded screenshots.
Scanned documents add a complication. A scan may look like a flat image, but once OCR runs, the file can gain a searchable text layer. If you redact only the visible image area and ignore OCR output, the text may still survive in extraction or search.
Use a process like this:
- Identify sensitive content on the page itself, not just obvious fields.
- Check repeated appearances of the same entity across headers, footers, attachments, and appendices.
- Inspect scans after OCR because the machine-readable text may not align perfectly with the visible image.
- Include non-text elements like stamps, photos, and screenshots that contain names or identifiers.
If a document will later be indexed, summarized, or searched, treat OCR output as part of the document, not as a side effect.
For files that need flattening after annotation or editing, a dedicated PDF flattening tool is useful because it helps collapse interactive or layered elements into a final distributable page state before release.
Later in the workflow, visual flattening still needs sanitation and verification. Flattening alone is not the whole job.
Here’s a video walkthrough if you want to see the mechanics in a familiar PDF workflow:
Burn in the changes and flatten the result
This is the step people skip when they think “apply redaction” and “draw rectangle” are the same thing.
They’re not.
A proper redaction tool applies the mark and then burns it into the document so the underlying content is removed, not covered. In many workflows that also means regenerating or stripping the text layer, then cleaning up metadata before export.
A good operator habit is to add reason labels or codes for each redaction in sensitive workflows. That isn’t just bureaucracy. It makes review easier and gives downstream teams a way to understand why content was withheld.
What usually fails here:
| Bad method | Why it fails |
|---|---|
| Rectangle overlay | Original text often remains underneath |
| Screenshot export of page | Can hide content visually but create downstream OCR problems |
| Partial flatten only | Can preserve metadata or text layer content |
| Re-save without inspection | Keeps hidden objects, comments, or attachments |
The result you want is simple: a release file that contains only the information you intend to disclose.
Sanitizing Hidden Data and Metadata
Even after visible redaction is done, the file may still be carrying sensitive material in places users never see. At this stage, careful teams catch the leaks that casual workflows miss.
Best-practice guidance warns that metadata and hidden content are a main technical pitfall. It advises sanitising the document to remove metadata, attached files, and embedded content that could expose sensitive information after visual redaction, as described in Loughborough University’s Adobe redaction guidance.
What counts as hidden data
Hidden data is broader than document properties.
It can include:
- Metadata such as author name, creation details, edit history, and software identifiers
- Comments and annotations that still reference the removed text
- Tracked changes in Word-derived files
- Attachments and embedded files packaged inside the document
- Form fields and hidden layers that don’t show in normal viewing
- OCR text layers generated from scans
- Accessibility tags or alternate text that still describe redacted content
In regulated environments, legal, healthcare, and privacy teams often get burned. A page can look perfectly clean while the file still exposes patient details, reviewer notes, or a hidden attachment. If you work in that kind of setting, this guide for AI-powered law firms is worth reading because it connects document handling with broader compliance expectations.
What to remove before release
A useful discipline is to think in two passes. First remove what a reader can see. Then remove what software can extract.
A practical sanitation checklist:
- Strip document properties before export. Don’t leave author, company, or edit metadata if the file is going outside your boundary.
- Remove comments and annotations rather than hiding them.
- Delete attachments and embedded objects if they’re not required for the release.
- Rebuild or scrub the text layer where the redacted content used to exist.
- Inspect metadata directly with a dedicated PDF metadata tool or the equivalent in your document software.
- Export the final releasable version only after sanitation, not before.
Hidden content is still content. If a parser can read it, a recipient can eventually read it too.
For Word and office-originated files, convert with caution. Comments, revisions, and document history often survive format changes in surprising ways. If the file started life outside PDF, assume there’s more to scrub than what the page preview shows.
Redacting Scanned Documents and OCR Text
Scanned files are where most redaction pipelines quietly break. A scan arrives as pixels, so the black box you draw looks final — there is no text layer to leak. Then OCR runs, and the document grows one.
The order of operations decides whether you are safe:
- OCR before redaction means the text layer already exists when you draw the box. Cover the pixels and the recognized characters stay behind in the layer, fully searchable and copyable. This is the single most common way a “redacted” scan leaks.
- OCR after redaction is safe only if the redaction destroyed the pixels. If it did, OCR has nothing to recognize in that region.
- OCR somewhere downstream — in a search index, an eDiscovery platform, a RAG pipeline — is the case teams forget entirely, because it happens on a copy they are not looking at.
A safe order for scanned redaction
- Work from the duplicate, as with any other redaction.
- Destroy the pixels first. Composite the region out of the page image rather than drawing a filled shape on top of it. If the operation would still show the original underneath when the annotation is deleted, it is not redaction.
- Discard any pre-existing text layer rather than editing it. A scan that already went through OCR carries a full transcript; the reliable move is to drop that layer entirely and re-run recognition against the redacted image.
- Re-run OCR on the redacted output and read the result. This is the verification step, not a formality — the new text layer is exactly what a search index will see.
- Diff the two transcripts. Every string you intended to remove should appear in the before and be absent from the after. That diff is your evidence.
Verify the OCR output, not the page
Reviewing a redacted scan visually tells you almost nothing, because the failure mode is invisible by construction. Extract and read instead:
# Re-OCR the redacted page and search the recovered text for anything
# that should be gone. Empty output is the passing result.
pdftotext statement-redacted.pdf - | grep -iE "john@example|4111 ?1111|SSN"
Two adjacent gotchas worth checking on real files. OCR text rarely aligns pixel-perfectly with the visible glyphs, so a region sized tightly to the ink can leave the tail of a recognized word outside the box — pad the region rather than trimming it to fit. And a redacted region can still be reconstructed from a lower-resolution copy if your pipeline generated thumbnails or previews before redaction ran; those derivatives are separate artifacts and need to be regenerated or deleted, not assumed stale.
If the document is a scan that must stay searchable after release, accept that you are rebuilding the text layer rather than patching it. The redacted image is the source of truth, and the transcript is derived from it — never the other way around.
How to Verify Your Redaction Is Permanent
Most guides stop too early. They show how to place the mark, not how to prove the removed content is gone.
That gap matters because many guides explain how to draw black boxes but not how to verify that redaction is irreversible. Better advice emphasizes copy-paste tests, search tests, and metadata checks, as discussed in Apryse’s redaction guide.

Run tests that try to break your redaction
Verification should feel adversarial. Assume the file is unsafe until it passes basic extraction attempts.
Run checks like these:
-
Copy-paste test
Select the redacted region or surrounding lines and paste into a text editor. If the hidden text appears, the document failed. -
Search test
Search the PDF for the terms you intended to remove. Also search for known fragments, not just full names. -
Metadata inspection
Open document properties and inspect for author info, comments, attachments, and embedded content. -
Layer or object inspection
Use a PDF editor that can reveal annotations, layers, and page objects. If the black box is a separate object above text, that’s a problem. -
Accessibility review
Check whether assistive technology or exported text can still access the removed content. -
Second-reviewer pass
Have another person inspect the final release file, especially for high-risk disclosures.
Make verification part of release, not an optional check
Teams get into trouble when verification is treated as extra QA instead of part of the definition of done.
A lightweight release gate helps:
| Check | Pass condition |
|---|---|
| Search | Redacted terms are not discoverable |
| Copy-paste | No hidden text can be extracted |
| Metadata | No sensitive properties or attachments remain |
| Reviewer signoff | Another person approves the releasable copy |
A redacted file that hasn’t been tested is only presumed safe.
That sounds strict, but it’s cheaper than handling a disclosure incident after the file has been emailed, indexed, or posted publicly.
Automating Redaction for Your Application with an API
If you’re building document features into a product, desktop redaction doesn’t solve the core engineering problem. You need a repeatable path from upload to sanitized output, with the same checks every time.
Where API-based redaction fits
API-based workflows make sense when users upload files into your app and those files move through storage, sharing, extraction, OCR, or AI features. The main benefit isn’t novelty. It’s consistency. Your app can run the same redaction and release pipeline for every document instead of relying on an operator to remember each step.
A typical flow looks like this:
- Upload the source document
- Store the returned file identifier
- Submit redaction instructions or patterns
- Generate a sanitized derivative
- Run automated verification checks
- Share only the approved output
If you also need a stable document URL during the workflow, a hosted PDF endpoint helps. okraPDF’s PDF hosting flow is a good example of the pattern developers usually want: upload once, keep a file identifier, and build later steps on top of the same file rather than re-uploading it for every operation.
A practical API workflow
At the API layer, keep the contract explicit. Don’t just send “redact this.” Send coordinates, terms, page ranges, or entity types, then return a new artifact rather than mutating the original in place.
A simple curl shape might look like this:
# 1. Upload the source document
DOC_ID=$(curl -s -X POST https://api.okrapdf.com/v1/documents \
-H "Authorization: Bearer $OKRA_API_KEY" \
-F "file=@statement.pdf" | jq -r '.id')
# 2. Redact regions on a page. The response is the composited page image,
# already flattened — the pixels under each region are gone, not covered.
curl -X POST "https://api.okrapdf.com/v1/documents/$DOC_ID/redact" \
-H "Authorization: Bearer $OKRA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"page": 2,
"regions": [
{ "x": 120, "y": 240, "w": 180, "h": 28 },
{ "x": 120, "y": 300, "w": 220, "h": 28 }
],
"format": "image/png"
}' --output statement-p2-redacted.png
And the same idea in JavaScript:
const res = await fetch(
`https://api.okrapdf.com/v1/documents/${docId}/redact`,
{
method: "POST",
headers: {
Authorization: `Bearer ${process.env.OKRA_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
page: 2,
regions: [{ x: 120, y: 240, w: 180, h: 28 }],
format: "image/png",
}),
},
);
// The body is image bytes, not JSON — store it as a new artifact.
const redactedPage = Buffer.from(await res.arrayBuffer());
Two things about this contract are deliberate, and they map onto the rules earlier in this post. It takes coordinates, not a search string, so you decide what goes — nothing is inferred on your behalf and silently missed. And it returns a composited image, which is the burn-in step from the workflow above: there is no text layer left under the box to recover, because there is no text layer at all.
That last property is also the trade-off. A flattened page image is irreversible, but it is no longer searchable or selectable, and it is not accessible to a screen reader until you pair it with a text alternative. For a page that must stay machine-readable after redaction, extract the text you intend to keep, drop the spans you don’t, and rebuild — rather than shipping an image and calling it done.
The production detail that matters most is output handling. Treat the redacted file as a separate artifact with its own lifecycle, permissions, and verification record.
If you want to try the burn-in step before wiring the API, okraPDF’s redaction tool removes regions in the browser and hands back a flattened file. For the PDF-specific version of this walkthrough — permanently removing text and metadata from a PDF — see how to redact a PDF.