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,
{ continued: true }
);
doc.textRight( 'RIGHT ALIGNED TEXT' );
doc.textCenter( 'CENTERED TEXT' );
doc.textBox(
[
'My favourite color is ',
{ text: 'red', color: 'red' }
],
{ align: 'right' }
);
doc.imageCenter(
'image.png',
230,
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!