community postAL Developmentcommunity - not Microsoftreviewed - checked by Opus

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

Yun Zhu · 2025-10-24 · 679 words · about 3 min

"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.

No source states these links: they share an object, a model read them, or a person found the same subject.

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.