PDFKit-自定义字体-fs.readFileSync不是函数 [英] PDFKit - Custom Fonts - fs.readFileSync is not a function
问题描述
我正在为应用程序使用PDFKit.我只是在带有HTML文件的浏览器中使用Java脚本(没有Node.js).
I'm using PDFKit for an application. I'm just using it in the Browser in an HTML file, with Javascript (no Node.js).
我从GitHub下载了PDFKit: https://github.com/devongovett/pdfkit/releases
I downloaded PDFKit from GitHub: https://github.com/devongovett/pdfkit/releases
以及Blob Stream: https://github.com/devongovett/blob-stream
as well as Blob Stream: https://github.com/devongovett/blob-stream
我正在尝试根据文档添加自定义字体,如下所示:
I'm trying to include a custom font per the documentation like so:
doc.registerFont('Custom Font', 'fonts/GOODDP__.TTF');
doc.font('Custom Font').fontSize(fontSize).text($("#text1").val(), xPos, yPos, configObj);
但我总是会收到此错误:
But I always get this error:
fs.readFileSync is not a function
这很有意义,因为fs.readFileSync
是node.js的一部分,而我没有使用它.但是,文档中的示例说这可以在浏览器中使用.
This makes sense because fs.readFileSync
is part of node.js, and I'm not using that. However, the example in the docs say this can be used in the browser.
我知道还有一个Browserify选项,但是我不确定在这种情况下如何或是否有帮助
I know there's also a Browserify option, but I'm not sure how or if that would help in this situation
推荐答案
似乎您必须使用Browserify来实现此功能,并且使用预编译的PDFKit.js不会对任何特定于Node.js的内容进行裁剪功能.
It seems you must use Browserify for this functionality and that using a pre-compiled PDFKit.js won't cut it for any of the Node.js-specific functionality.
这篇关于PDFKit-自定义字体-fs.readFileSync不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!