Building a Word to PDF Converter in Next.js — Server-Side DOCX Text Extraction with Mammoth and PDF Generation with PDFKit
javascript
dev.to
Converting a .docx file to PDF server-side comes down to two steps: extract the text content from the DOCX format, then build a new PDF from that text. The Word to PDF converter uses mammoth.js for extraction and PDFKit for generation — both running in a Next.js API route. Why Server-Side? DOCX is a ZIP archive containing XML files. Parsing it client-side is possible but adds ~500KB to the bundle (mammoth is not small). Server-side keeps the bundle clean, and the conversion runs in N