super-pdfkit
Enhanced pdfkit with some useful methods
(thx to: pdfkit, pdfkit-table and textbox-for-pdfkit authors)
Easy usage:
const PDF = require( 'super-pdfkit' );
const doc = new PDF( {
margin: 50,
pageNum: true,
pageNumText: 'Page ',
header( thisDoc ) {
thisDoc.textCenter( 'HEADER', 15 );
thisDoc.imageCenter( 'header.png', { width: 50 } );
},
footer( thisDoc ) {
thisDoc.textCenter( 'FOOTER', thisDoc.page.height - 40 );
}
} );
doc.textLeft(
'LEFT ALIGNED TEXT',
200,
{ width: 100 }
)
.marginRight( 70 )
.textRight( 'RIGHT ALIGNED TEXT' );
.textCenter( 'CENTERED TEXT' )
.marginRight( 50 )
.textBox(
[
'My favourite color is ',
{ text: 'red', color: 'red' }
],
{ align: 'right' }
)
.imageCenter(
'image.png',
300,
100
);
doc.marginedWidth();
const marginLeft = doc.marginLeft();
doc.marginLeft( marginLeft );
doc.end();
doc.end( thisDoc => {
for ( let i = 0; i < 40; i++ ) {
thisDoc.text( 'ANY EDIT ON THE DOCUMENT' );
}
} );
doc.complete()
.then( bufferData => console.log( bufferData ) );
Show the example!