Dynamics 365 Business Central: How to get the page number of a PDF or Word file in AL (Display the page count on Attached Documents and Doc. Attachment List Factbox)
This post explains how to retrieve and display page counts for PDF and Word documents in Business Central using AL code. It covers using the PDF Document codeunit to get page counts directly for PDFs and converting Word files to PDF first, with examples for extending document attachment pages.

post Dynamics 365 Lab
"By default, Business Central does not display the page count of these files, but if we want to display it, is there any way?"
Key points
- Codeunit 3110 ‘PDF Document’ has a GetPdfPageCount method that returns the page count of a PDF stream
- Word files must first be converted to PDF with Document Report Mgt. ConvertWordToPdf
- A PageCount field is added to the Document Attachment table and shown on the Document Attachment Details page and the Doc. Attachment List Factbox
- A subscriber to OnBeforeSaveAttachment fills in the page count when a file is uploaded; for Word files it first copies the data into a second Temp Blob
Quotes
- “By default, Business Central does not display the page count of these files, but if we want to display it, is there any way?” (Identifies the problem that motivates the solution of displaying page counts in document attachments)
- “For Word files, we need to convert them to PDF first.” (Explains the key limitation that Word files require conversion before page counting is possible)
AL objects mentioned
As named in the post. A name that matches one object page by exact type and name links to it; the others stay as named.
- codeunit 3110 “PDF Document”
- codeunit 419 “File Management”
- codeunit 9651 “Document Report Mgt.”
- codeunit 4100 “Temp Blob”
- table 1173 “Document Attachment”
- page 1173 “Document Attachment Details”
- page 1178 “Doc. Attachment List Factbox”
Possibly related
No source states these links: they share an object, a model read them, or a person found the same subject.
- Attachment capabilities and limitations (preview) — possibly related: names Codeunit 4100 “Temp Blob”
- Business Central 2025 wave 2 (BC27): Support for new ExtendedDataType value: Document (display/preview a PDF as a portrait image in FactBox) — possibly related: both name Codeunit 3110 “PDF Document”
- Dynamics 365 Business Central: Convert Word (.docx) To HTML (.html) within BC (No control add-in and APIs) — possibly related: both name Table 1173 “Document Attachment”
- Dynamics 365 Business Central: Convert Word (.docx) To PDF (.pdf) within BC (No control add-in and APIs) — possibly related: both name Page 1173 “Document Attachment Details”
- Dynamics 365 Business Central: Generate Swiss QR Code without external services/APIs — possibly related: both name Codeunit 4100 “Temp Blob”
- Dynamics 365 Business Central: How to prevent users from uploading duplicate files as attachments (Duplicate file names) — possibly related: both name Table 1173 “Document Attachment”
- Dynamics 365 Business Central: How to preview Word (.docx) in web client without downloading (No control add-in and APIs) — possibly related: both name Codeunit 9651 “Document Report Mgt.”
- Dynamics 365 Business Central: How to quickly strip not supported chars in File Name via AL — possibly related: both name Codeunit 419 “File Management”
- Dynamics 365 Business Central: previewing PDF files in web client using the new ExtendedDataType = Document. — possibly related: both name Codeunit 419 “File Management”
- New Application Ideas of Dynamics 365 Business Central (2025 MAY) — possibly related: both name Table 1173 “Document Attachment”
Context
- Features: PDF page count retrieval, Word to PDF conversion, document attachment extensions, attachment metadata display, event subscriber implementation
Source: Dynamics 365 Lab - Yun Zhu, community blog. Summary, key points and quotes are derived (CONTENT-NOTICE.md); read the original for the full text.