Headers and footers

<< Click to Display Table of Contents >>

Navigation:  EasyPDFMaker documentation > Getting started > Step by Step > Working with PDF file >

Headers and footers

Previous pageReturn to chapter overviewNext page

Page headers and footers can be: static or dynamic.

 

They use the same syntax:

 

 dd.PageHeader('simple text')

 dd.PageFooter('"columns": ["Left part", {{ "text": "Right part", "alignment": "right" }]')

 

 

[=== compare with pdfmake:

var docDefinition = {

header: 'simple text',

 

footer: {

  columns: [

    'Left part',

     { text: 'Right part', alignment: 'right' }

   ]

 },

 

content: (...)

};

===]

 

 

For dynamically generated content (including page numbers, page count and page size) you can return a value from TakePageHeader and TakePageFooter virtual methods:

 

! TakePageHeader

RETURN '{{ "text": "'& sDocTitle &'", "alignment": "center", "fontSize": 16 }'

 

! TakePageFooter

RETURN '{{ "text": "Page '& currentPage &'/'& pageCount &'", "alignment": "right", "fontSize": 10, "margin": [20, 0] }'

 

 

[=== compare with pdfmake:

var docDefinition = {

footer: function(currentPage, pageCount) { return currentPage.toString() + ' of ' + pageCount; },

header: function(currentPage, pageCount, pageSize) {

   // you can apply any logic and return any valid pdfmake element

 

  return [

     { text: 'simple text', alignment: (currentPage % 2) ? 'left' : 'right' },

     { canvas: [ { type: 'rect', x: 170, y: 32, w: pageSize.width - 170, h: 40 } ] }

   ]

 },

(...)

};

===]