// use npm package and initialise the pdfMake.
const pdfMake = require('pdfmake/build/pdfmake.js')
const pdfFonts = require('pdfmake/build/vfs_fonts.js')
pdfMake.vfs = pdfFonts.pdfMake.vfs
function showPDF() {
const statHeader = { text: data in header not the Header
header,bold: true}
const content = preparePDF(yourHTML)
const statFooter = 'data in footer not Footer footer, To add a
footer check the pdfMake documentation for footer.'
const name = ''
const docDefinition = {
// Add page count
footer: function (currentPage, pageCount) {
return {
margin: 10,
columns: [{ text: currentPage.toString() + ' of ' +
pageCount, alignment: 'center' }]
}
},
header: { text: name, style: 'gameName' },
content: [
statHeader,
content,
statFooter
],
styles: {
gameName: {
fontSize: 16,
bold: true,
alignment: 'left',
margin: [40, 20, 0, 80]
}
}
}
// creates pdf formated file with give name.
pdfMake.createPdf(docDefinition).download(`${name}.pdf`)
}
Wrap it in a function like
const htmlToPDF = require('html-to-pdfmake')
function preparePDF (yourHTML) {
let htmltoPDFData = []
const html = <div>yourHTML</div>
htmltoPDFData = htmlToPDF(html)
return htmltoPDFData
}