Tuesday, April 5, 2016

Creating PDF using Pdfmake - Introduction

Pdfmake follows a declarative approach. You don't need to calculate positions manually like: writeText(text, x, y), moveDown etc..., as you other libraries do.

You just need to create document-definition-object like this:
var docDefinition = { content: 'This is an sample PDF printed with pdfMake' };

You can add more stuffs to the object with multi-level tables, images, lists, paragraphs, margins, styles etc.  After you made the object, you can create the pdf and download it.

// open the PDF in a new window
pdfMake.createPdf(docDefinition).open();
// print the PDF (not working in this version, will be added back in a couple of days)
// pdfMake.createPdf(docDefinition).print();
// download the PDF
pdfMake.createPdf(docDefinition).download();

Pdfmake has following 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,
  • helper methods for opening/printing/downloading the generated PDF.
  • setting of PDF metadata (e.g. author, subject)
Source: 

No comments:

Post a Comment