Skip to content

Test whether bytes are a PDF

This operation is the low-level signature test used by every other guarded operation in PdfClientService, including Validate PDF bytes.

Field Value
Operation ID OP-03
Trigger Caller invokes IsPdf(byte[] file)
Inputs Byte array
Outputs true / false
Primary components PdfAPI.Core.PdfClientService.IsPdf
Entry point PdfAPI.Core\Services\PdfClientService.cs

Steps

  1. Return false when the argument is null. (BR-02)
  2. Decode the whole byte array as ASCII into a header string.
  3. Require length ≥ 5 and the first four bytes to be 0x25 0x50 0x44 0x46 (%PDF). (BR-01)
  4. Return whether the decoded header starts with "%PDF-". (BR-01)

Process flow

The following diagram visualizes this operation's control flow.

flowchart TD
    Start(["IsPdf(bytes)"]) --> Null{bytes null?}
    Null -->|Yes| False1([Return false])
    Null -->|No| Decode["Decode ASCII header"]
    Decode --> Len{length >= 5 and<br>starts with %PDF?}
    Len -->|No| False2([Return false])
    Len -->|Yes| Header{Header starts<br>with "%PDF-"?}
    Header -->|No| False3([Return false])
    Header -->|Yes| True([Return true])

Failure and edge-case behavior

  • Decoding the entire byte array as ASCII before inspecting only the first few bytes roughly doubles peak memory per call, which can pressure memory on large documents.*

Note: Statements marked with * were inferred from code structure, naming conventions, or contextual evidence where direct confirmation was not available in source artifacts.

Sources

  • PdfAPI.Core\Services\PdfClientService.cs