Skip to main content

Command Palette

Search for a command to run...

Today's npm package: pdfmake

Updated
โ€ข1 min read
P

I am developer from India currently based in Berlin, Germany.

I am very interested in Design, though I don't design ๐Ÿ˜‰ I take care of it while making my apps.

Photography, videography and having random conversation over beer are my activities of spare time. Timelapses and hyperlapses make me wonder all the time ๐Ÿ˜Š

Today's npm package is pdfmake

PDF is one of the most compatible ways to Share Documents and ensure formatting at the destination environment.

Today's package pdfmake will allow us to Create PDFs at Client Side and Server Side.

Let's see a basic code to make a PDF on the client side:

import pdfMake from "pdfmake/build/pdfmake";
import pdfFonts from "pdfmake/build/vfs_fonts";
pdfMake.vfs = pdfFonts.pdfMake.vfs;

const docDefinition = {
  content: [
    'By default paragraphs are stacked one on top of (or actually - below) another. ',
    'It\'s possible however to split any paragraph (or even the whole document) into columns.\n\n',
    'Here we go with 2 star-sized columns, with justified text and gap set to 20:\n\n',
    {
      alignment: 'justify',
      columns: [
        {
          text: 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Malit profecta versatur nomine ocurreret multavit, officiis viveremus'
        },
        {
          text: 'Lorem ipsum dolor sit amet, consectetur adipisicing elit.'
        }
      ]
    },
    '\n\nWow, you\'ve read the whole document! Congratulations :D'
  ],
  styles: {
    header: {
      fontSize: 18,
      bold: true
    },
    bigger: {
      fontSize: 15,
      italics: true
    }
  },
  defaultStyle: {
    columnGap: 20
  }
}

pdfMake.createPdf(docDefinition).open();

And this will get us the following PDF as

PDF

pdf-preview.png

Stay tuned for tomorrow's package of the Day.

More from this blog

P

Pankaj Patel - @heypankaj_

63 posts

Sharing my learnings and thoughts on Blogging, Personal Branding and Programming