PDFTron html2pdf 0KB文件大小

问题描述

我在Mac上的测试节点(Hapi)应用程序中安装了@pdftron节点模块。我正在尝试从HTML字符串生成PDF文件,但保存的文件为0 KB。我已经尝试过两种方法:

  • 通过在GET处理程序中为路由实现示例代码 在index.js中配置
  • 通过运行以下示例脚本 安装在 node_modules/@pdftron/pdfnet-node/samples/HTML2PDFTest/NODEJS/HTML2PDFTest.js

在这两种情况下,所有已保存的新PDF的大小均为0KB,应该由该过程修改的任何现有PDF均保持不变。

我检查了html2pdf模块库路径是否正确设置。

路由处理程序代码如下,与PDFTRon提供的示例代码一致。

server.route({
    method: 'GET',path: '/pdftron/html',handler: (request,h) => {

        const { PDFNet } = require('@pdftron/pdfnet-node/lib/pdfnet.js')

        const main = async () => {
            await PDFNet.initialize()
            await PDFNet.HTML2PDF.setModulePath('node_modules/@pdftron/pdfnet-node/lib')
            const output_path = '/tmp/'

            try {

                const html2pdf = await PDFNet.HTML2PDF.create();
                const doc = await PDFNet.PDFDoc.create();
                const html = '<html><body><h1>Heading</h1><p>Paragraph.</p></body></html>'
        
                html2pdf.insertFromHtmlString(html);
                await html2pdf.convert(doc);
                doc.save(output_path.concat('pdf2html.pdf'),PDFNet.SDFDoc.SaveOptions.e_linearized);

            } catch (err) {
                console.log(err)
            }

        }
    
        PDFNet.runWithCleanup(main,0).then(function () { PDFNet.shutdown(); })
        return 'PDF2HTML Test'
    }
})

任何想法/建议将不胜感激。

解决方法

有关此问题的更新-我从PDFTron获得反馈,说当前稳定的Mac OS版本的发行版存在问题,并且他们正在解决该问题。

同时,他们向我指出了每晚进行实验的here版本。我下载并安装了最新的实验版本,现在使用该版本保存PDF文件。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...