RegEx Patterns

Processor lets you create redactions on top of text matching a provided regular expression via the createRedactions operation. This is the most versatile of redaction creation strategies. For example, to redact any email address in the “pspdfkit.com” domain, you could use the following:

{
  "type": "createRedactions",
  "strategy": "regex",
  "strategyOptions": {
    "regex": "\\d+"
  }
}

See the Available Operations guide for details regarding the regular expression syntax and escaping rules.

Applying Redactions

After redaction annotations are created, they need to be applied to the document to effectively and permanently remove the covered content. You can achieve this by adding the applyRedactions operation to the operations pipeline.

ℹ️ Note: The applyRedactions operation is always executed as the last step in the operations pipeline, regardless of its actual position in the list of operations.

See the following sections for usage examples. Before you get started, make sure Processor is up and running.

Creating and Applying Redactions in a File on Disk

Send a request to the /process endpoint, attaching an input file and the operations JSON:

curl -X POST http://localhost:5000/process \
  -F file=@/path/to/example.pdf \
  -F operations='{
  "operations": [
    {
      "type": "createRedactions",
      "strategy": "regex",
      "strategyOptions": {
        "regex": "\\d+"
      }
    },
    {
      "type": "applyRedactions"
    }
  ]
}' \
  -o result.pdf 
POST /process HTTP/1.1
Content-Type: multipart/form-data; boundary=customboundary

--customboundary
Content-Disposition: form-data; name="file"; filename="example.pdf"
Content-Type: application/pdf

<PDF data>
--customboundary
Content-Disposition: form-data; name="operations"
Content-Type: application/json

{
  "operations": [
    {
      "type": "createRedactions",
      "strategy": "regex",
      "strategyOptions": {
        "regex": "\\d+"
      }
    },
    {
      "type": "applyRedactions"
    }
  ]
}
--customboundary--

This will create redaction annotations and apply them to the file, removing the content beneath them.

Creating and Applying Redactions in a File from a URL

Send a request to the /process endpoint and include a URL pointing to the file you want to redact:

curl -X POST http://localhost:5000/process \
  -F url=https://pspdfkit.com/downloads/examples/credit-card-application.pdf \
  -F operations='{
  "operations": [
    {
      "type": "createRedactions",
      "strategy": "regex",
      "strategyOptions": {
        "regex": "\\d+"
      }
    },
    {
      "type": "applyRedactions"
    }
  ]
}' \
  -o result.pdf 
POST /process HTTP/1.1
Content-Type: multipart/form-data; boundary=customboundary

--customboundary
Content-Disposition: form-data; name="url"

https://pspdfkit.com/downloads/examples/credit-card-application.pdf
--customboundary
Content-Disposition: form-data; name="operations"
Content-Type: application/json

{
  "operations": [
    {
      "type": "createRedactions",
      "strategy": "regex",
      "strategyOptions": {
        "regex": "\\d+"
      }
    },
    {
      "type": "applyRedactions"
    }
  ]
}
--customboundary--

This will create redaction annotations and apply them to the file, removing the content beneath them.