如何在电子合同模板中写入动态数据?
需求是,公司有些业务需要和用户签订电子合同。合同内容会根据业务数据变化而变化,比如订单金额、购买数量等。有没有做过这种的朋友?
9 回复
@vendar 用的易签宝,那边没有提供这个,github上 的pdfkit和jspdf都是把HTML转pdf,不支持向模板写入动态数据。感觉这个算是蛮常见的需求,竟然没有找到这种包
没用过易签宝。不过你这个问题也很好解决,html你可以用模板生成吧?复杂的找个模板引擎,简单点自己进行变量替换就行。然后通过pdfkit之类的把动态生成的html转成pdf即可。
来自✨ Node.js开源项目精选✨
最后解决方案是,用了hummus-recipe模块。
const path = require('path');
const HummusRecipe = require('hummus-recipe');
const pdfDoc = new HummusRecipe('test.pdf', 'new.pdf', {
fontSrcPath: path.join(__dirname, '../../fonts')
});
pdfDoc
// edit 1st page
.editPage(2)
.text('T王T宝强T', 176.5, 204.3, {font: 'PMingLiU'})
.endPage()
pdfDoc.editPage(1)
.text('刘德华 ', 187.0 + 36.5, 133.4 + 24.7, {font: 'PMingLiU'})
.endPage()
// end and save
pdfDoc.endPDF();