Skip to content

Validate a document

This operation extends Validate PDF bytes to a Document-level guard: it requires a non-null document, loads its bytes, optionally deletes the source file, then re-runs the byte-level PDF signature check.

Field Value
Operation ID OP-02
Trigger Caller invokes ValidatePdf(Document document, PdfOptions options)
Inputs Document, PdfOptions
Outputs Returns without a value on success; throws PdfException on failure; may delete the source file as a side effect
Primary components PdfAPI.Core.PdfClientService.ValidatePdf(Document, PdfOptions)
Entry point PdfAPI.Core\Services\PdfClientService.cs

Steps

  1. If document is null, throw PdfException("No document was specified."). (BR-04)
  2. On failure: aborts before any file I/O occurs.
  3. Call document.Load() to materialise bytes from File or from FilePath. (BR-05)
  4. Delegates to Load a document.
  5. If the load failed, throw PdfException("The document could not be loaded."). (BR-06)
  6. If options is null or options.CleanupInputFile is true, call document.Delete() to remove the on-disk source file. (BR-07)
  7. Delegates to Persist and remove a document.
  8. This deletion happens before step 5's signature check, so a document that later fails validation has already lost its on-disk copy.
  9. Run Validate PDF bytes against the in-memory bytes. (BR-01, BR-02, BR-03)

Process flow

The following diagram visualizes this operation's control flow.

flowchart TD
    Start(["ValidatePdf(document, options)"]) --> Null{document null?}
    Null -->|Yes| ErrNull(["Throw PdfException:<br>No document was specified"])
    Null -->|No| Load["document.Load()"]
    Load --> Loaded{Loaded?}
    Loaded -->|No| ErrLoad(["Throw PdfException:<br>could not be loaded"])
    Loaded -->|Yes| Cleanup{options null or<br>CleanupInputFile?}
    Cleanup -->|Yes| Delete["document.Delete()"]
    Cleanup -->|No| Validate
    Delete --> Validate["OP-01: ValidatePdf(bytes)"]
    Validate -->|Invalid| ErrInvalid([Throw PdfException])
    Validate -->|Valid| Ok([Return])

Failure and edge-case behavior

  • Deleting the source file before validating its content means rejected input files are unrecoverable after this operation runs (BR-07).
  • A null PdfOptions is treated identically to CleanupInputFile = true.

Sources

  • PdfAPI.Core\Services\PdfClientService.cs
  • PdfAPI.Core\Document.cs
  • PdfAPI.Core\PdfOptions.cs