[英]How to make a pdf file with node js using a custom font from a local file?
I tried all library and tricks possibles, I tested everything found on the web, but nothing worked so... I need to make a pdf file with node js using a custom font from a local file. 我尝试了所有的库和技巧,测试了Web上的所有内容,但是没有任何效果。。。我需要使用本地文件中的自定义字体,使用node js创建pdf文件。 The font format is otf.
字体格式是otf。 Nothing more to tell you :x
没什么可告诉您的:x
To generate PDF file from Node.js, I can advise you to do it from a HTML template. 要从Node.js生成PDF文件,我建议您从HTML模板中进行操作。
To do this, I'm using this library: phantom-html-to-pdf . 为此,我使用了这个库: phantom-html-to-pdf 。
Here is an example of usage : 这是用法示例:
const fs = require('fs');
const htmlTopdf = require('phantom-html-to-pdf')();
let html = fs.readFileSync('./template.html');
htmlTopdf({html: html}, function(err, pdf) {
if (err) {
console.log(err);
}
else {
pdf.stream.pipe(fs.createWriteStream('./destination.pdf'));
}
});
Hope it helps. 希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.