pdfmake
Client/server side PDF printing in pure JavaScript
A JavaScript library that generates PDF documents from a structured definition object, running in both web browsers and Node.js with support for tables, images, fonts, and page layouts.
pdfmake is a JavaScript library that generates PDF documents. It works in two environments: inside a web browser, where it can create a PDF directly on the user's device, and on a server running Node.js, where it can generate PDFs as part of a back-end process.
The library is driven by a document definition object. Instead of drawing on a page pixel by pixel, developers describe what a document should contain, including paragraphs, tables, images, lists, headers, and footers, and pdfmake handles all the layout calculations. It supports text alignment (left, right, centered, or justified), numbered and bulleted lists, tables with configurable column widths, column and row spans, automatically repeated table headers across page breaks, and a newspaper-style column layout where content flows from one column to the next.
Other capabilities include embedded fonts, custom margins and page sizes, portrait or landscape orientation, a table of contents, multi-level nested structures, and document-level metadata such as author and subject fields. Page headers and footers can show static text or dynamic content that references the current page number and total page count. The library also provides helper functions to open a generated PDF in a new browser tab, print it directly, or trigger a file download.
pdfmake is built on top of another library called pdfkit, which handles the lower-level PDF construction. An interactive playground is available online where developers can test document definitions in real time without installing anything. The library is released under the MIT license.
Where it fits
- Generate a downloadable PDF invoice or report directly in the browser without any server round-trip
- Build a Node.js service that creates formatted PDF documents like receipts, letters, or certificates
- Add a print-to-PDF button to a web app that produces documents with tables, custom fonts, and page numbers