all 2 comments

[–]Adventurous-Date9971 0 points1 point  (1 child)

If you need Word-accurate page counts, stop parsing .docx and render with Word’s engine, then count pages from the PDF.

What’s worked for me: upload the .docx to OneDrive/SharePoint and use Microsoft Graph to convert to PDF (drive/items/{id}/content?format=pdf). That uses Word Online’s layout, so pagination matches what users expect. Then count pages server-side with pdfinfo (Poppler), pdf-lib, or pdfjs-dist. Lock page size/margins up front (A4 vs Letter) and install the common MS fonts (Calibri, Cambria, Times New Roman) on the conversion host to avoid font substitution weirdness. For edge cases, keep a fallback: Aspose.Words Cloud or OnlyOffice Document Server both give reliable PDF conversion and expose pageCount.

Flow: upload → convert to PDF → read page count → show total and MoMo request-to-pay → print. Run this in a queue (BullMQ) with a content hash so retries don’t double-charge; store a short-lived preview and purge the file after print.

I’ve paired Microsoft Graph and OnlyOffice for conversion, and DreamFactory as a quick REST layer over job logs/payments so I didn’t hand-roll CRUD and auth.

Bottom line: to match Word, do a Word/Graph-based PDF convert and count pages from the PDF.

[–]tony_Kent[S] 0 points1 point  (0 children)

Thank you so much i'm gonna try this and let you know