DEV Community

Michael Lip
Michael Lip

Posted on • Originally published at zovo.one

Word to PDF Conversion: Why the Output Never Looks Quite Right

You write a document in Word, export to PDF, and the formatting shifts. Bullets misalign. Fonts substitute. Page breaks move. Headers land in unexpected places. This happens because Word and PDF are fundamentally different formats with different rendering models, and the conversion is inherently lossy.

Why the formats are different

Word (.docx) is a flow layout format. Content flows to fill the available space. When you change the page size, margin, or font, the text reflows. A Word document does not specify absolute positions for text -- it specifies structure (paragraphs, headings, lists) and style (font, size, spacing), and the rendering engine figures out where everything goes.

PDF is a fixed layout format. Every character has an exact position on the page, specified in points from the bottom-left corner. A PDF is essentially a description of what the printed page looks like, down to the pixel. There is no reflow -- the layout is frozen.

Converting from flow layout to fixed layout requires the converter to simulate Word's rendering engine: applying fonts, calculating line breaks, positioning floats, and paginating. Any difference between the converter's rendering and Word's rendering produces a visual discrepancy.

Common conversion issues

Font substitution. If the PDF converter does not have access to the same fonts as Word, it substitutes. Times New Roman becomes a different serif font. The substituted font has slightly different character widths, which changes line breaks, which changes page breaks. Embedding fonts in the PDF prevents this.

Complex tables. Word's table layout algorithm is notoriously complex (it has to balance column widths, merged cells, and text wrapping). Different converters implement this algorithm differently, leading to tables that render with different column widths or cell padding.

SmartArt and diagrams. Word's SmartArt objects are vector graphics stored in a proprietary format. Not all converters render these correctly. The safest approach is to group and convert SmartArt to a standard image before exporting.

Math equations. Word's equation editor (OMML format) may not convert to PDF math notation correctly. Some converters rasterize equations (converting them to images), which loses scalability and sharpness.

Headers and footers. Dynamic content like page numbers, dates, and section headings in headers/footers require the converter to understand Word's section model. Simple headers convert fine. Headers with different first-page formatting or section-specific headers sometimes break.

The best conversion approaches

Print to PDF from Word itself. Using Word's built-in "Save as PDF" or "Print to PDF" produces the most accurate results because it uses Word's own rendering engine to generate the fixed layout. If you have access to Microsoft Word, this is always the best option.

LibreOffice. The open-source alternative. Its rendering engine is different from Word's, so complex documents may shift. But for simple to moderately formatted documents, the results are good. Available on all platforms and can be automated from the command line.

libreoffice --headless --convert-to pdf document.docx
Enter fullscreen mode Exit fullscreen mode

Browser-based conversion. Uses JavaScript libraries to parse the .docx format (which is XML inside a ZIP file) and render it to PDF. The parsing is reasonably accurate, but the rendering often lacks full fidelity for complex formatting.

The .docx format under the hood

A .docx file is a ZIP archive containing XML files:

document.xml     -- the main content
styles.xml       -- style definitions
numbering.xml    -- list numbering definitions
[Content_Types].xml -- MIME type mappings
word/media/      -- embedded images
Enter fullscreen mode Exit fullscreen mode

Understanding this structure is useful for programmatic document generation and processing. Libraries like python-docx, docx4j, and mammoth.js parse and manipulate these XML files directly.

I built a Word to PDF converter at zovo.one/free-tools/word-to-pdf-converter that converts .docx files to PDF in the browser without uploading to a server. It parses the XML structure, renders the content with formatting, and generates a downloadable PDF. For simple to moderately formatted documents, it produces clean results. For complex documents with advanced formatting, Word's native export remains the gold standard.

I'm Michael Lip. I build free developer tools at zovo.one. 500+ tools, all private, all free.

Top comments (0)