Inspect and flatten PDF form fields¶
Provides two related utilities: detecting whether a PDF has AcroForm fields, and flattening those fields (making them non-editable) when present.
| Field | Value |
|---|---|
| Operation ID | OP-SFC-013 |
| Trigger | PdfAPI\Services\PdfService.cs:38 and :45, used when the caller opts out of the remote client |
| Inputs | byte[] PDF |
| Outputs | bool (HasFormFields) or byte[] (Flatten) |
| Primary components | PdfHelper.HasFormFields, PdfHelper.Flatten |
| Entry point | PdfApi.SyncFusionCore\PdfHelper.cs |
Steps¶
HasFormFields: load the bytes as aPdfLoadedDocumentinside ausingand returndoc.Form != null(BR-SFC-034).Flatten: load the bytes as aPdfLoadedDocument; whendoc.Form != null, setForm.Flatten = true, save to aMemoryStreamand return the new bytes (BR-SFC-035).- If the document has no form: return the original input bytes unchanged (BR-SFC-036).
Process flow¶
The following diagram visualizes this operation's control flow.
flowchart TD
Start(["HasFormFields or Flatten<br>called with PDF bytes"]) --> Load["Load bytes as<br>PdfLoadedDocument"]
Load --> Which{"Which call?"}
Which -->|HasFormFields| CheckForm{"doc.Form != null?"}
CheckForm -->|Yes| ReturnTrue([Return true])
CheckForm -->|No| ReturnFalse([Return false])
Which -->|Flatten| CheckForm2{"doc.Form != null?"}
CheckForm2 -->|Yes| SetFlatten["Set Form.Flatten = true,<br>save to MemoryStream"]
SetFlatten --> ReturnFlattened([Return flattened bytes])
CheckForm2 -->|No| ReturnOriginal(["Return original bytes<br>unchanged"])
Failure and edge-case behavior¶
- A PDF with no
Formpresent is a normal, non-error outcome for both methods:HasFormFieldsreturnsfalseandFlattenreturns the input unchanged.
Related documentation¶
Sources¶
PdfApi.SyncFusionCore\PdfHelper.csPdfAPI\Services\PdfService.cs