Skip to content

CLI Tool

Marc Jones edited this page Dec 30, 2025 · 1 revision

CLI Tool: pdfer

The pdfer command-line tool provides scripted access to PDF redaction, search, and verification.

Installation

# Build the CLI tool
cd PdfEditor.Redaction.Cli
dotnet build

# Run directly
dotnet run -- <command> [options]

# Or publish as executable
dotnet publish -c Release -o ./publish
./publish/pdfer <command> [options]

Commands

redact

Redact text from a PDF file.

pdfer redact <input.pdf> <output.pdf> --text "SENSITIVE"
pdfer redact <input.pdf> <output.pdf> --text "NAME" --text "ADDRESS"
pdfer redact <input.pdf> <output.pdf> --pattern "SSN:\s*\d{3}-\d{2}-\d{4}"

Options:

Option Description
--text <text> Text to redact (can be repeated)
--pattern <regex> Regex pattern to redact
--case-sensitive Match case exactly
--page <n> Redact only on page n (1-based)

Examples:

# Redact a name from all pages
pdfer redact form.pdf redacted.pdf --text "John Doe"

# Redact multiple terms
pdfer redact form.pdf redacted.pdf --text "SSN" --text "123-45-6789"

# Redact using regex
pdfer redact form.pdf redacted.pdf --pattern "\d{3}-\d{2}-\d{4}"

search

Search for text in a PDF file.

pdfer search <input.pdf> --text "SEARCH_TERM"
pdfer search <input.pdf> --pattern "REGEX"

Options:

Option Description
--text <text> Text to search for
--pattern <regex> Regex pattern to search for
--case-sensitive Match case exactly
--json Output results as JSON

Output:

Found 3 matches for "CONFIDENTIAL":
  Page 1: "CONFIDENTIAL" at (100.5, 234.2)
  Page 1: "CONFIDENTIAL" at (100.5, 456.8)
  Page 3: "CONFIDENTIAL" at (200.1, 123.4)

verify

Verify that text is NOT present in a PDF (redaction verification).

pdfer verify <input.pdf> --text "SENSITIVE"

Options:

Option Description
--text <text> Text that should NOT be present
--pattern <regex> Pattern that should NOT match

Exit codes:

  • 0: Verification passed (text not found)
  • 1: Verification failed (text found)
  • 2: Error (file not found, etc.)

Example:

# Verify redaction was successful
pdfer redact input.pdf output.pdf --text "SECRET"
pdfer verify output.pdf --text "SECRET"
echo $?  # Should be 0

info

Display information about a PDF file.

pdfer info <input.pdf>
pdfer info <input.pdf> --json

Output:

File: document.pdf
Pages: 5
PDF Version: 1.7
Producer: PDFsharp 6.2.2
Creator: Microsoft Word
Title: Sample Document
Has Text: Yes
Estimated Text Length: 12,456 characters

Scripting Integration

Shell Scripts

#!/bin/bash
# Batch redact all PDFs in a directory

for pdf in *.pdf; do
    echo "Processing: $pdf"
    pdfer redact "$pdf" "redacted_$pdf" --text "CONFIDENTIAL"
    pdfer verify "redacted_$pdf" --text "CONFIDENTIAL"
    if [ $? -ne 0 ]; then
        echo "ERROR: Verification failed for $pdf"
        exit 1
    fi
done
echo "All files processed successfully"

PowerShell

# Batch processing in PowerShell
Get-ChildItem *.pdf | ForEach-Object {
    $output = "redacted_$($_.Name)"
    pdfer redact $_.FullName $output --text "CONFIDENTIAL"
    if ($LASTEXITCODE -ne 0) {
        Write-Error "Redaction failed for $($_.Name)"
    }
}

JSON Output for Automation

# Get search results as JSON for processing
pdfer search document.pdf --text "CONFIDENTIAL" --json | jq '.matches[]'

Exit Codes

Code Meaning
0 Success
1 Operation failed (verification failed, text not found, etc.)
2 Error (file not found, invalid arguments, etc.)

Test Coverage

The CLI tool has 74 passing tests covering:

  • All command parsing
  • Redaction operations
  • Search functionality
  • Verification logic
  • Error handling
  • JSON output

Run tests:

cd PdfEditor.Redaction.Cli.Tests
dotnet test

Last updated: 2024-12-29

Clone this wiki locally