npm pdfmake 0.1.17

latest releases: 0.3.0-beta.8, 0.2.10, 0.3.0-beta.7...
9 years ago

Features:

  • Introduce new styling properties marginLeft, marginRight, marginTop, and marginBottom.
  • Add the capability to have switch of page orientation per page.
  • Adds an editorconfig.
  • Adding possibility to specify line height.
  • Access to internal pages array, to have better testing capabilities.
  • Dynamically control page breaks, for instance to avoid orphan childs.

Bug Fixes:

  • Add the type to the font name for pdfkit. This is to avoid using the same type (normal, bold, italics, bolditalics) every time a font is requested. Fixes #162.
  • Use function for vLineColor if provided on table layout. Fixes #166.

Introduce new styling properties marginLeft, marginRight, marginTop, and marginBottom.

An element in the document definition can now specify margin on any side individually. This allows to combine margins from different styles.

 {
  content: [
    {text: 'text with style 1', style: ['style1']},
    {text: 'text with style 2', style: ['style2']},
    {text: 'text with both styles', style: ['style1', 'style2']}
  ], 
  styles: {
   style1: {
       marginTop: 30
   }, 
   style2: {
       marginLeft: 20
    }
  }
}

Add the capability to have switch of page orientation per page.

This allows a document to switch between landscape and portrait in a document.

    {
      pageOrientation: 'portrait',
      content: [
        {text: 'Text on Portrait'},
        {text: 'Text on Landscape', pageOrientation: 'landscape', pageBreak: 'before'},
        {text: 'Text on Landscape 2', pageOrientation: 'portrait', pageBreak: 'after'},
        {text: 'Text on Portrait 2'},
      ]
    }

Important you need to specify a page break on the same node, to make sure the page can switch it's orientation.

Adds an editorconfig.

An .editorconfig file makes sure that coding conventions, especially whitespaces, are kept within each editor.

Adding possibility to specify line height.

A new style property lineHeight is now available.

    {
      content: [{text: 'this is a very long text', lineHeight: 1.5}]
    }

lineHeight is a relative value.

Access to internal pages array, to have better testing capabilities.

This allows writing integration test agains a array of pages in PDF Make.

pdfMake.createPdf(docDefinition)._getPages({}, function(pages){
  assert.equal(pages.length, 2);
});

Dynamically control page breaks, for instance to avoid orphan childs.

You can now specify a pageBreakBefore function, which can determine if a page break should be inserted before the page break. To implement a 'no orphan child' rule, this could like like this:

var dd = {
    content: [
       {text: '1 Headline', headlineLevel: 1},
       'Some long text of variable length ...',
       {text: '2 Headline', headlineLevel: 1},
       'Some long text of variable length ...',
       {text: '3 Headline', headlineLevel: 1},
       'Some long text of variable length ...',
    ],
  pageBreakBefore: function(currentNode, followingNodesOnPage, nodesOnNextPage, previousNodesOnPage) {
     return currentNode.headlineLevel === 1 && followingNodesOnPage.length === 0;
  }
}

If pageBreakBefore returns true, a page break will be added before the currentNode. Current node has the following information attached:

{
   id: '<as specified in doc definition>', 
   headlineLevel: '<as specified in doc definition>',
   text: '<as specified in doc definition>', 
   ul: '<as specified in doc definition>', 
   ol: '<as specified in doc definition>', 
   table: '<as specified in doc definition>', 
   image: '<as specified in doc definition>', 
   qr: '<as specified in doc definition>', 
   canvas: '<as specified in doc definition>', 
   columns: '<as specified in doc definition>', 
   style: '<as specified in doc definition>', 
   pageOrientation '<as specified in doc definition>',
   pageNumbers: [2, 3], // The pages this element is visible on (e.g. multi-line text could be on more than one page)
   pages: 6, // the total number of pages of this document
   stack: false, // if this is an element which encapsulates multiple sub-objects
   startPosition: {
     pageNumber: 2, // the page this node starts on
     pageOrientation: 'landscape', // the orientation of this page
     left: 60, // the left position
     right: 60, // the right position
     verticalRatio: 0.2, // the ratio of space used vertically in this document (excluding margins)
     horizontalRatio: 0.0  // the ratio of space used horizontally in this document (excluding margins)
   }
}

Don't miss a new pdfmake release

NewReleases is sending notifications on new releases.