Skip to content
PressJetDocs Docs v0.1.0-beta.9 GitHub
Edit this page
Source docs v0.1.0-beta.9 Install v0.1.0-beta.7
On this page

Permanently redact a PDF

Use the local PressJet CLI to remove sensitive content from an unsigned PDF. It renders every page at 144 dpi, replaces the selected pixels with black, and writes a new image-only PDF. The output contains no source text layer, tags, bookmarks, interactive fields, attachments, metadata, optional layers, thumbnails, or incremental revisions. Visible material outside the selected regions is preserved as pixels. Keep the original if you need its selectable text, form fields, or accessibility structure.

Inspect a plan before applying it

Create selectors.json with the selections you need. This example searches for an exact phrase on every page, matches a case-sensitive regular expression on page 2, and masks an image and a rectangle on page 1.

{
  "version": 1,
  "selectors": [
    {"type": "text", "text": "Confidential project"},
    {"type": "regex", "pattern": "ACCT-[0-9]{6}", "page": 2},
    {"type": "image", "page": 1, "occurrence": 2},
    {"type": "rectangle", "page": 1, "x": 32, "y": 48, "width": 150, "height": 22}
  ]
}
head -c 32 /dev/urandom > plan.key && chmod 600 plan.key
pressjet redact plan original.pdf selectors.json plan.json --plan-key-file plan.key
pressjet redact preview original.pdf plan.json preview.pdf --plan-key-file plan.key
pressjet redact apply original.pdf plan.json redacted.pdf --plan-key-file plan.key

Before applying, inspect all the pages in the preview against the original. The preview has the same masked pixels as the final PDF, plus a banner. A preview may contain sensitive material you have yet to select. Keep the original, selectors, plan, and preview within the same trust boundary. The plan contains region coordinates and a digest of the original, and PressJet refuses it against any differing source bytes.

The plan ID is an HMAC-SHA256 of the plan under the plan key. preview, apply and batch accept a plan only with the key that issued it, so an edited plan, for example one with pages added to reviewedPages, is refused even if its ID is recomputed. Without --plan-key-file, plan, preview, apply and batch use your own key at $XDG_CONFIG_HOME/pressjet/redaction-plan.key (or ~/.config/pressjet/redaction-plan.key), made from the system's random number generator on first use with mode 600 in a folder with mode 700. That key is refused if it is a symbolic link, if another user owns it or its folder, if other users can access it ("run chmod 600 on it"), or if other users can change its folder ("run chmod 700 on it"). A key in a folder you cannot write is still used. When HOME is not set the flag is required. To share plans between people or machines, pass --plan-key-file <file> to every command of the workflow: a file of 32 to 1024 secret bytes, used as is (make one with head -c 32 /dev/urandom > plan.key). Keep it private (mode 600; a key file that other users can access draws a warning) and away from the plans: anyone who can read it can issue plans. A plan issued under another key is refused with "a plan issued under another plan key; build a new plan".

  • rectangle uses points (1/72 of an inch), with the origin at the top left of the displayed crop box after page rotation. Page numbers start at 1.
  • page masks the entire displayed page. It retains the page in the output.
  • image counts visible-page paint occurrences in interpretation order, starting at 1. Omit occurrence to select every occurrence on the page. A mask uses the occurrence's bounding rectangle, including overlapping material.
  • text matches case-sensitive Unicode-normalized text and collapses whitespace. regex uses Rust regex syntax with the same normalized page text. Backreferences, look-around, and empty matches are refused. Text matches do not span pages. Omit page on either selector to search every page.
  • Document metadata is discarded for every output. For a metadata-only rebuild, use {"version":1,"selectors":[],"scrubMetadata":true}. Metadata drawn visibly on a page requires a region mask.

Search works with supported, positioned PDF text. Scans, outlines drawn as paths, unusual encodings, or nontrivial reading order may require rectangles, image selections, or full-page masks. Use the original and preview to check all selected terms and supplemental regions. The plan's review entries identify pages with indicators such as raster content, missing text mappings, or ambiguous text order. vectorTextPossible marks a page that may show text drawn as vector shapes, which search cannot see: a page with more than 40 glyph-shaped paths (filled, stroked, or used as a clipping path) in text rows and no searchable text under them, as text converted to outlines produces, and, for a text or regex selector without a page, every page where that selector found nothing but which holds a glyph-sized vector shape (a curved or slanted outline up to an inch tall) without searchable text under it. Rules, borders, table cells, bars, barcodes and 2D codes have straight, axis-aligned edges and are not counted. The check has limits: glyphs drawn only with straight, axis-aligned edges (some pixel or stencil fonts) are not counted either, and outlined text that is rotated or set vertically does not form the rows the first rule looks for, so inspect such pages yourself. To acknowledge a flagged page after inspecting and correcting its regions, add that page number to reviewedPages in the request and generate a new plan and preview. A selector that had no matches appears in unmatchedSelectors using its one-based request index. Replace that selector with a region verified against the original before applying.

Apply several plans

Build and inspect each plan first, with the same key file. Each job runs independently. Paths are relative to the manifest's folder and must stay inside it: a job whose path is absolute, contains .., or leads outside the folder through a symbolic link fails with invalid_path and writes nothing.

{
  "version": 1,
  "jobs": [
    {"input": "original.pdf", "plan": "plan.json", "output": "batch-redacted.pdf"}
  ]
}
pressjet redact batch batch.json --plan-key-file plan.key

Each job runs in a child process of its own with the full time budget, one after another, so a batch can take up to the number of jobs times PRESSJET_REDACTION_TIMEOUT_MS.

The command prints one JSON summary with a result per job. A failed job reports invalid_path, invalid_input (the PDF cannot be read), invalid_plan (the plan cannot be read), redaction_refused (the plan does not apply: another source, another key, unmatched selectors, pages awaiting review, or a limit) or output_error. Its exit status is nonzero if any job fails. Successful jobs remain available, and failed jobs publish no new output. All CLI modes create private files and refuse to overwrite any destination.

Limits and compatibility

Redaction accepts up to 32 MiB of source bytes, 20 pages, 32 selectors, 256 regions, and eight prior incremental revisions. The default pixel budget is 24 million across all pages, configurable through PRESSJET_MAX_PIXELS up to a redaction ceiling of 35 million. Output is bounded by the engine response limit. Planning, previewing and applying each stop after 30 seconds ("Redaction time budget exceeded"); the CLI reads PRESSJET_REDACTION_TIMEOUT_MS (100 to 600 000). The clock is read between pages, every 256 drawing operations while a page is read or measured, and before and after each page is rasterized. Rasterizing one page cannot be interrupted, so it is bounded by two budgets instead, and the time budget can be overrun by up to one page's rasterization. Before any page is interpreted, the content operators the document would run, with every form, soft mask and annotation appearance expanded as many times as it is drawn, are counted from the document's structure and capped at 2 million (the largest 17-page document in PressJet's test corpus needs about 124 000); a tiling pattern counts its cell for every paint, and a Type 3 font (selected by Tf or a graphics state's /Font) its largest glyph for every byte shown, after it is selected, including in the forms drawn after that; each shown byte counts as one paint plus the most paints any Type 3 glyph of the document makes, counting the glyphs of text that glyphs show in turn (a font whose glyphs show text in itself, or glyphs making more than 4 096 paints, are refused). Functions are refused when one evaluation would run more than 1 024 calculator (Type 4) operators or 4 096 steps in all, or a sampled function holds more than about a million values. Shadings are charged for every device pixel they cover times the work of one evaluation of their functions, in the drawing-work budget where the measuring pass sees them and, in pattern cells, soft masks and Type 3 glyphs, for the largest page area against a budget of about a billion function operations, which also counts the tables of Separation colour spaces and transfer functions and the per-pixel tint transforms of DeviceN images. A form that draws itself is refused, and so is a Type 3 font whose glyph looks up resources when neither the glyph nor the font has any ("The PDF has content redaction cannot bound before rendering"). Before any page is rasterized, the drawing work of all pages is measured against a budget of 20 million units: each path, clip, image and transparency group costs its elements plus the pixels its bounding box covers on the page divided by 1 024, each glyph 16 and each decoded image pixel 1/64 (the largest 17-page document in the corpus measures about 1.05 million). An image that, with its masks, would decode to more than 64 Mi pixels is refused wherever it is drawn (pages, forms, tiling patterns, soft masks, Type 3 glyphs and annotation appearances), and so is a document whose image drawings together decode more than 256 Mi pixels; the size is the declared one, the Columns of CCITT data, or the size in the header of JPEG 2000 and JBIG2 data (which are measured only when they are the stream's single filter). Both budgets refuse with "Redaction budget exceeded". Dashed strokes are charged one unit per dash along the whole path, and mesh shadings are limited to about 262 000 triangles (a patch counts as the 722 triangles it is split into) and charged for the device pixels of each triangle's box on the page. Content streams are read one operator at a time and refused once one passes the operator cap, and the walk over the document visits at most about 16.8 million drawing events. Neither refusal leaves output.

These static bounds are best effort and do not model every rendering cost. The pressjet redact commands therefore interpret and render every PDF in a child process of their own, which limits its own memory (PRESSJET_REDACTION_HEAP_MB, default 1 024, range 16 to 65 536) and processor time (PRESSJET_REDACTION_CPU_MS, default the time budget, rounded up to whole seconds) and is killed when the time budget has passed. A child stopped by any of these limits makes the command fail with redaction_resources_exceeded, and nothing is written; files are written only by the parent, after the child has succeeded. Encrypted inputs (even with an empty user password), PDFs with signature evidence or unsupported revision history, and renderer-reported incomplete output are refused. Decrypt an encrypted input first, for example with qpdf --decrypt in.pdf out.pdf.

The original rectangle array command continues to work. It uses the same rasterization and masking path.

pressjet redact original.pdf rectangles.json redacted.pdf

Rust callers can use plan_redaction, preview_redaction, and apply_redaction from the engine with in-memory PDF bytes and explicit Limits. These issue and accept plans under a random key generated once per process, so a plan is valid only in the process that issued it, and a restart invalidates outstanding plans. To keep plans across processes or restarts, pass RedactionOptions::default().with_plan_key(RedactionPlanKey::new(&secret)?) to plan_redaction_with, preview_redaction_with and apply_redaction_with, or to pressjet::Renderer::with_redaction_options, and keep the secret out of the plan's storage. RedactionOptions::with_maximum_millis sets the time budget (default 30 000; u64::MAX sets none), and redact_flattened_with takes the same options for rectangle-only redaction. RedactionReviewReason and RedactionError are non-exhaustive: match them with a wildcard arm. The same interfaces compile for wasm32-wasip1. The batch manifest and file handling belong to the native CLI. The engine and SDK functions run in the calling process, where no memory or processor limit can be set, so their bounds are the static ones above: redact untrusted PDFs through pressjet redact, or call the functions in a subprocess you limit yourself.