流星应用程序中pdfmake中的服务器端字体目录 [英] server side fonts directory in pdfmake in meteor app

查看:78
本文介绍了流星应用程序中pdfmake中的服务器端字体目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在服务器上创建并保存 pdf.我在服务器端使用过meteorhacks:npm 打包并安装了pdfmake.

I am trying to create and save a pdf on the server. I have used meteorhacks:npm packaged and installed pdfmake on the server side.

我的代码位于服务器目录下的子目录中.我仅使用示例来确保我可以生成基本的 pdf.

My code is in a subdirectory under server directory. I am using just the example to make sure I can generate a basic pdf.

 var fonts = {
                Roboto: {
                    normal: 'fonts/Roboto-Regular.ttf',
                    bold: 'fonts/Roboto-Medium.ttf',
                    italics: 'fonts/Roboto-Italic.ttf',
                    bolditalics: 'fonts/Roboto-Italic.ttf'
                }
            };
            var PdfPrinter = Meteor.npmRequire('pdfmake/src/printer');
            var printer = new PdfPrinter( fonts );

            var dd = {
                content: [
                    'First paragraph',
                    'Another paragraph'
                ]
            };
            var pdfDoc = printer.createPdfKitDocument(dd);
            pdfDoc.pipe(fs.createWriteStream('basics.pdf')).on('finish',function(){
                //success
            });
            pdfDoc.end();

我得到了

 Error: ENOENT, no such file or directory 'fonts/Roboto-Regular.ttf'

我对我的字体目录应该在哪里感到有些困惑.

I am a bit baffled as to where my fonts directory should be.

我试图调试 pdfmake 库并迷路了.把字体目录放在了不同的地方,没有运气.

I tried to debug the pdfmake library and got lost. Placed the fonts directory in various places with no luck.

有什么想法吗?

推荐答案

下载roboto字体并在根目录下创建fonts文件夹,粘贴这些依赖文件.

download roboto font and create fonts folder in the root directory and paste these dependent files.

这篇关于流星应用程序中pdfmake中的服务器端字体目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆