Reputation: 1366
I'm using this code for header in my generated pdf,
but even though the header is removed for pages after the first page, the top margin is still reserved by docDefinition.pageMargins = [10,120,10,70]
Is there a way to remove the top margin on pages > 1?
docDefinition.header = function(page, pages) {
if(page>1) return {};
return {
columns: [
{
image: logo,
height: 90
},
{
stack: [
{text: 'Some title'},
{text: 'Some other row'}
]
}
],
height:100,
margin: [10,10],
}
}
Upvotes: 4
Views: 7089
Reputation: 809
Here's how you can display header/footer for specific pages in PDFMake
Simple Example
header: function(page) {
if (page != 1)
return {text: 'Other page footer'}
else
return {text: 'Page 1 footer'}
}
Complex Example
footer: function(page) {
if (page != 1){
return { columns: [
[{
canvas: [
{
type: 'line',
x1: 0,
y1: 5,
x2: 510,
y2: 5,
lineWidth: 1,
},
],
alignment: 'left',
margin: [50, -10, 0, 0],
},
{
style: 'footer',
text: [
'This is a demo footer -',
{
text: 'For PDFMake',
color: '#ed3833',
},
],
},
{
canvas: [
{
type: 'line',
x1: 0,
y1: 5,
x2: 510,
y2: 5,
lineWidth: 0.8,
},
],
alignment: 'left',
margin: [50, -2, 0, 0],
},
{
alignment: 'left',
margin: [527, 5, 0, 0],
fontSize: 8,
text: ['© 2021'],
},]
]}
}
},
Upvotes: 0
Reputation: 1795
header: (currentPage, pageCount) => {
if (currentPage != 1) {
{
columns: [
{
text: 'Header text',
fontSize: 15,
style: { alignment: 'left', color: '#3c3c3c' },
bold: true,
},
]
},
// return header;
}
},
you can check it with currentPage != 1
Upvotes: 3