我正在尝试使用pdfmake生成带有水印的pdf。但是,使用属性" watermark:' test'",pdf未生成。弹出错误控制台说"字体'未定义'在风格'正常'没有在文档定义的字体部分中定义"。如何使用PDFMAKE JS库生成带有水印的PDF。
<html>
<head>
<script src='https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.20/pdfmake.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.20/vfs_fonts.js'></script>
<script type="text/javascript">
function myFunction()
{
var docDefinition = {
watermark:'test',
background: 'simple text',
content: 'This is an sample PDF printed with pdfMake'
};
pdfMake.createPdf(docDefinition).download('Report.pdf');
}
</script>
</head>
<body>
<button type="button" onclick="myFunction()">Click Me!</button>
</body>
</html>
答案 0 :(得分:1)
在较新版本的pdfMake中解决了这个问题,请确保使用的是最新版本,它可以正常使用。
function myFunction() {
var docDefinition = {
watermark: 'test',
background: 'simple text',
content: 'This is an sample PDF printed with pdfMake'
};
pdfMake.createPdf(docDefinition).download('Report.pdf');
}
&#13;
<script src='https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.31/pdfmake.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.31/vfs_fonts.js'></script>
<button type="button" onclick="myFunction()">Click Me!</button>
&#13;