What is pdfmake?
The pdfmake npm package is a server-side and client-side library for generating PDF documents from a JSON-based structure. It provides a declarative API that allows developers to layout text, images, vectors, and other elements in a PDF document.
What are pdfmake's main functionalities?
Text and Typography
This feature allows you to add text to your PDF with various typography settings such as font size, style, and weight.
{"content": [{"text": "Hello World", "style": "header"}], "styles": {"header": {"fontSize": 18, "bold": true}}}
Lists
With this feature, you can create ordered and unordered lists within your PDF document.
{"content": [{"ul": ["Item 1", "Item 2", "Item 3"]}]}
Tables
This feature allows you to insert tables into your PDF, with customizable rows, columns, and styling.
{"content": [{"table": {"body": [["Column 1", "Column 2", "Column 3"], ["Value 1", "Value 2", "Value 3"]]}}]}
Images
This feature enables you to embed images in your PDF documents, with support for various formats and base64 encoded sources.
{"content": [{"image": "data:image/jpeg;base64,...", "width": 200}]}
Vector Graphics
With vector graphics, you can draw shapes and paths to create custom illustrations and designs in your PDF.
{"content": [{"canvas": [{"type": "rect", "x": 0, "y": 0, "w": 100, "h": 100, "color": "#E53935"}]}]}
Other packages similar to pdfmake
html-pdf
html-pdf is a Node.js package that converts HTML to PDF. It uses PhantomJS as a rendering engine. Unlike pdfmake, which uses a JSON structure, html-pdf allows you to define your PDF layout using HTML and CSS.
pdf-lib
pdf-lib is a library for creating and modifying PDF documents in any JavaScript environment. It provides low-level PDF manipulation capabilities and differs from pdfmake by offering more control over the PDF creation process at the expense of a steeper learning curve.
pdfmake
PDF document generation library for server-side and client-side in pure JavaScript.
Check out the playground and examples.
This is unstable master branch for version 0.3.x, for stable use version 0.2.x see branch 0.2 or older version 0.1.x see branch 0.1.
Features
- line-wrapping,
- text-alignments (left, right, centered, justified),
- numbered and bulleted lists,
- tables and columns
- auto/fixed/star-sized widths,
- col-spans and row-spans,
- headers automatically repeated in case of a page-break,
- images and vector graphics,
- convenient styling and style inheritance,
- page headers and footers:
- static or dynamic content,
- access to current page number and page count,
- background-layer,
- page dimensions and orientations,
- margins,
- custom page breaks,
- font embedding,
- support for complex, multi-level (nested) structures,
- table of contents,
- helper methods for opening/printing/downloading the generated PDF,
- setting of PDF metadata (e.g. author, subject).
Documentation
Documentation URL: https://pdfmake.github.io/docs/
Source of documentation: https://github.com/pdfmake/docs Improvements are welcome!
Building from sources
using npm:
git clone https://github.com/bpampuch/pdfmake.git
cd pdfmake
npm install
npm run build
using yarn:
git clone https://github.com/bpampuch/pdfmake.git
cd pdfmake
yarn
yarn run build
License
MIT
Authors
pdfmake is based on a truly amazing library pdfkit (credits to @devongovett).
Thanks to all contributors.