Count pages¶
This operation counts pages by scanning decoded PDF markup for /Type /Page markers, rather than parsing the PDF object graph.
| Field | Value |
|---|---|
| Operation ID | OP-05 |
| Trigger | Caller invokes GetPageCount(byte[] file) |
| Inputs | PDF bytes |
| Outputs | Integer page count |
| Primary components | PdfAPI.Core.PdfClientService.GetPageCount, FindPageCount |
| Entry point | PdfAPI.Core\Services\PdfClientService.cs |
Steps¶
- Run Validate PDF bytes to guard the input. (BR-01, BR-02, BR-03)
- Decode the bytes as UTF-8 into a string.
- Count regex matches of
/Type\s*/Page[^s]in the decoded markup and return the count. (BR-09) - If the decoded text is null: return
0.
Process flow¶
The following diagram visualizes this operation's control flow.
flowchart TD
Start(["GetPageCount(bytes)"]) --> Guard["OP-01: ValidatePdf"]
Guard --> Decode["Decode UTF-8"]
Decode --> Count["Count /Type /Page<br>regex matches"]
Count --> Return([Return integer count])
Failure and edge-case behavior¶
- This counts page objects by scanning raw markup rather than parsing the PDF object graph, so compressed object streams or a
/Type /Pagetoken inside a content stream can skew the count.*
Note: Statements marked with
*were inferred from code structure, naming conventions, or contextual evidence where direct confirmation was not available in source artifacts.
Related documentation¶
Sources¶
PdfAPI.Core\Services\PdfClientService.cs