npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

printmaker

v0.1.0-pretest.1

Published

Generate PDF documents and from JavaScript objects

Downloads

4

Readme

PDF Maker

PDF Maker is a library for generating PDF documents in JavaScript.

  • Easy to use: document contents are defined in plain objects.
  • Works anywhere: Browser, Node.js, Deno.
  • TypeScript support: types included in the npm package.

This project is heavily inspired by pdfmake and builds on pdf-lib and fontkit. It would not exist without the great work and the profound knowledge contributed by the authors of these projects.

Usage

The function makePdf() creates PDF data from a given document definition.

Basic Example

const fontData = await readFile('Roboto-Regular.ttf');
const fontDataBold = await readFile('Roboto-Medium.ttf');
const pdfData = await makePdf({
  // Fonts must be registered (see below)
  fonts: {
    Roboto: [
      { data: fontData },
      { data: fontDataBold, bold: true },
    ],
  },
  // Page margins (`x` is a shorthand for left and right)
  margin: { x: '2.5cm', top: '2cm', bottom: '1.5cm' },
  // Content as an array of paragraphs
  content: [
    // Paragraphs can contain text and text attributes
    { text: 'Lorem ipsum', bold: true, textAlign: 'center', fontSize: 24 },
    // Text can also be an array of text ranges with different attributes
    { text: [
        'dolor sit amet, consectetur adipiscing elit ',
        { text: 'sed do eiusmod', italic: true },
        ' tempor, incididunt ut labore et dolore magna aliqua.',
      ]
    },
  ],
});
await writeFile(`hello.pdf`, pdfData);

Fonts

All fonts are embedded in the PDF and need to be registered with the fonts attribute. Font data is accepted in .ttf or .otf format, as ArrayBuffer, Uint8Array, or base64-encoded string. Each font family can include different variants that are selected based on the attributes bold and italic.

const documentDefinition = {
  fonts: {
    // The `fontFamily` name of the font
    'DejaVu-Sans': [
      // TTF / OTF font data as Uin8Array or base64 encoded string
      { data: fontDataDejaVuSansNormal },
      { data: fontDataDejaVuSansBold, bold: true },
      { data: fontDataDejaVuSansItalic, italic: true },
      { data: fontDataDejaVuSansBoldItalic, bold: true, italic: true },
    ],
    'Roboto': [
      { data: fontDataRobotoNormal },
      { data: fontDataRobotoMedium, bold: true },
    ]
  },
  content: [
    { text: 'lorem ipsum', fontFamily: 'Roboto', bold: true }, // will use Roboto Medium
    { text: 'dolor sit amet' }, // will use DejaVu-Sans (the font registered first), normal
  ]
};

Images

JPG images are supported. All images need to be registered with the images attribute. Images can be used more than once in the document without multiplying the image's footprint in the created PDF. The size of an image can be confined using the width and height attributes.

const documentDefinition = {
  images: {
    'logo': { data: imageData }
    …
  },
  content: [
    { image: 'logo', width: 200, height: 100 },
    …
  ]
};

Content

The content attribute of the document definition accepts an array of top-level blocks that can be text paragraphs, images, column layouts or row layouts. Page breaks will only occur between top-level blocks.

Columns

To arrange blocks horizontally, they can be included in a block with a columns attribute. When columns have a width attribute, it will be respected. The remaining space will be distributed evenly across all columns.

{
  columns: [
    {text: 'Column 1', width: 100}, // 100 pt wide
    {text: 'Column 2'}, // gets half of the remaining width
    {text: 'Column 3'}, // gets half of the remaining width
  ],
}

Rows

A rows layout can be used to group multiple rows in a single block, e.g. to apply common attributes to them or to include them in a surrounding columns layout.

{
  rows: [
    {text: 'Row 1'},
    {text: 'Row 2'},
    {text: 'Row 3'},
  ],
  textAlign: 'right',
}

Documentation

There is no generated documentation yet, please refer to content.ts for an overview and specification of all supported attributes in a document definition.

Example

A more extensive example is included in the examples/ folder.

Run npm start to generate a PDF in the out/ folder on every change of this file.

License

MIT