DataMasque Portal

PDF Document Masking

The unstructured_text mask can be applied to PDF documents (.pdf) via mask_file tasks. Text is extracted from the document, entities are detected and masked, then the document is rebuilt with the masked text in place.

How It Works

PDF masking follows a three-stage pipeline:

  1. Extraction - Text spans, images, and vector drawings are extracted from each page.
  2. Masking - Entities in the extracted text are detected and masked. Images and drawings are handled according to their respective settings.
  3. Rebuild - A new PDF is constructed from the masked content.

Rebuilding minimises the risk of PII preservation through metadata or hidden content. Document metadata is stripped, and only masked content is carried into the output.

Supported Content

The following elements are extracted and rebuilt:

  • Text spans alongside positions
  • Fonts, if available for extraction within the PDF, alongside size, style, and colour
  • Images (PNG, JPEG, etc.) with original position and dimensions preserved
  • Vector drawings (lines, quads, etc.) with colour, opacity, line width, and dash patterns

image_handling

Controls how raster images are handled in PDF documents. Note that this parameter also affects Word document masking, and has no effect on text columns.

Value Description
redact (default) Replaces all images with a black rectangle of the same dimensions.
retain Preserves original images.

drawing_handling

Controls how vector drawings (lines including table borders, shapes, paths) are handled in PDF documents. This parameter only applies to PDF document masking and has no effect on Word documents or text columns.

Value Description
redact (default) Removes all vector drawings from the output.
retain Preserves original vector drawings.

Vector drawings include lines, rectangles, curves, and arbitrary shapes drawn with PDF path operators. These are distinct from raster images -- drawings are defined as mathematical paths rather than pixel data.

When redact is selected, all vector drawing paths are removed from the rebuilt PDF. This is a removal operation rather than a replacement -- the space previously occupied by drawings will be empty in the output.

File Type Detection

PDF document masking is supported in two contexts:

  • In mask_file tasks, the file extension (.pdf) determines the file type.
  • In mask_table tasks, binary column values are inspected:
    • content containing %PDF- in the first 1024 bytes are treated as PDF documents.
    • This allows masking of PDF documents stored as blobs in database columns.

Limitations

  • Images may contain PII. This cannot be detected by text-based matchers
    • Use image_handling: redact (the default) when images might contain sensitive data.
  • Vector drawings may contain text rendered as paths or other PII. These cannot be detected by text-based matchers.
    • Use drawing_handling: redact (the default) when drawings might contain sensitive data.
  • PII split across multiple pages cannot be detected by the regex, checksum, or context_sources matchers.
    • Use ai_detect to improve detection of split PII.
  • In PDFs with tight line spacing, words at the start or end of a line may disappear after they are masked.
  • Password-protected PDFs will not mask. Trying to mask will return a document encrypted error.
  • Fonts are remapped to different fonts when the original cannot be preserved.
    • Text using non-standard font encodings may render as incorrect characters after remapping.
  • The space between characters may change when rebuilding documents with non-standard fonts, which may affect the flow of paragraphs.
  • Vector drawings are retained, though line thickness may differ from the original.
  • Unsupported scripts: Arabic, Devanagari and other Indian scripts, Geʽez, Hebrew, Khmer, Myanmar, Sinhala, Syriac, Thai, Tibetan.
    • Characters in these scripts will not render correctly in the masked PDF.
  • Masking can change the length of text causing masked values to overflow the original space occupied by the text.
  • Text and images rotated at angles other than multiples of 90° are repainted without the rotation.
  • Gradient (shading) fills are repainted in a flat average colour.
    • Gradient pattern fills over non-rectangular paths are omitted from the masked PDF.
  • The fallback mask for PDF documents only supports from_blob. Other fallback mask types are not supported for binary documents.