Skip to content

Read PDF version

This operation reports the %PDF-d.d version token declared in a PDF's header bytes.

Field Value
Operation ID OP-04
Trigger Caller invokes Version(byte[] file)
Inputs PDF bytes
Outputs Version string (e.g., "1.7"), or "" when not found
Primary components PdfAPI.Core.PdfClientService.Version
Entry point PdfAPI.Core\Services\PdfClientService.cs

Steps

  1. Run Validate PDF bytes to guard the input. (BR-01, BR-02, BR-03)
  2. Decode the bytes as ASCII, require length ≥ 8 and the %PDF magic bytes. (BR-01)
  3. Match %PDF-(?<version>\d+\.\d+) and return the captured version. (BR-08)
  4. Return an empty string when no match is found. (BR-08)

Process flow

The following diagram visualizes this operation's control flow.

flowchart TD
    Start(["Version(bytes)"]) --> Guard["OP-01: ValidatePdf"]
    Guard --> Header{length >= 8 and<br>%PDF magic bytes?}
    Header -->|No| Empty1(["Return \"\""])
    Header -->|Yes| Regex["Match %PDF-(version)"]
    Regex -->|Match| Return([Return version string])
    Regex -->|No match| Empty2(["Return \"\""])

Failure and edge-case behavior

  • Invalid PDF input aborts via PdfException at the guard step (BR-03) before any version parsing occurs.

Sources

  • PdfAPI.Core\Services\PdfClientService.cs