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¶
- If
documentis null, throwPdfException("No document was specified."). (BR-04) - On failure: aborts before any file I/O occurs.
- Call
document.Load()to materialise bytes fromFileor fromFilePath. (BR-05) - Delegates to Load a document.
- If the load failed, throw
PdfException("The document could not be loaded."). (BR-06) - If
optionsis null oroptions.CleanupInputFileis true, calldocument.Delete()to remove the on-disk source file. (BR-07) - Delegates to Persist and remove a document.
- This deletion happens before step 5's signature check, so a document that later fails validation has already lost its on-disk copy.
- 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
PdfOptionsis treated identically toCleanupInputFile = true.
Related documentation¶
Sources¶
PdfAPI.Core\Services\PdfClientService.csPdfAPI.Core\Document.csPdfAPI.Core\PdfOptions.cs