Skip to content

Validate PDF bytes

This operation is the common guard used by every other PdfClientService operation: it tests whether a byte array carries a PDF signature and aborts with a domain exception if it does not.

Field Value
Operation ID OP-01
Trigger Caller invokes ValidatePdf(byte[] file, string fileName = null)
Inputs PDF bytes, optional file name
Outputs Returns without a value on success; throws PdfException on failure
Primary components PdfAPI.Core.PdfClientService.ValidatePdf(byte[], string)
Entry point PdfAPI.Core\Services\PdfClientService.cs

Steps

  1. Call IsPdf(file) to test the byte array for a PDF signature. (BR-01, BR-02)
  2. If not a PDF, compose a message including the file name when one was supplied and throw PdfException. (BR-03)
  3. On failure: throws PdfException("ValidatePdf: The file '<name>' is not a valid pdf document.")
  4. If valid, return without a value.

Process flow

The following diagram visualizes this operation's control flow.

flowchart TD
    Start(["ValidatePdf(bytes, fileName)"]) --> Check["IsPdf(bytes)"]
    Check -->|false| Err([Throw PdfException])
    Check -->|true| Ok([Return])

Failure and edge-case behavior

  • A null byte array is never a valid PDF and always triggers the throw path (BR-02).
  • When no file name is supplied, the exception message omits the file name segment.

Sources

  • PdfAPI.Core\Services\PdfClientService.cs