我正在尝试从我用 angular 创建的视图创建一个 pdf。问题是pdf看起来像这样:
它不能计算出角度标记吗?
var docDefinition = { content: printHtml };
pdfMake.createPdf(docDefinition).download('optionalName.pdf');
// 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
}