【发布时间】:2018-08-29 10:30:54
【问题描述】:
我通过nodejs生成了pdf。我想在这个生成的 pdf 中添加水印。我在代码中使用了 dynamic-html-pdf 插件。如果有在 dynamic-html-pdf 中添加水印的任何选项。我在这里展示我的示例代码。
var path=require('path');
var pdf = require('dynamic-html-pdf');
var html='<!DOCTYPE html><html><head><style>';
html=html+'</style>';
html=html+'</head>';
html=html+'<body>';
html=html+'<div class="divstyle1" id="content">A computer is a device that can be instructed to carry out sequences of arithmetic or logical operations automatically via computer programming. </div>';
html=html+'</body></html>';
var options = {
format: "A4",
orientation: "portrait",
border: "10mm",
base: 'file://' + path.resolve('./public/graph') + '/'
};
var document = {
type: 'file',
template: html,
context: {
img:'./public/graph/logo.jpg'
},
path: "./public/graph/mypdf.pdf"
};
pdf.create(document, options)
.then(res => {
res.status(200).json({
message: 'pdf created'
});
})
.catch(error => {
res.status(200).json({
message: 'error'
});
});
【问题讨论】:
标签: javascript node.js node-html-pdf