使用JavaScript将docx/odt转换为PDF [英] Converting docx/odt to PDF using JavaScript

查看:268
本文介绍了使用JavaScript将docx/odt转换为PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个节点Web应用程序,需要将docx文件转换为pdf(仅使用客户端资源,不使用插件).通过使用docxjs将docx转换为HTML,然后使用jspdf(docx-> HTML-> PDF)将HTML转换为PDF,我找到了一种可能的解决方案.该解决方案可以实现,但是我遇到了几个问题,尤其是在渲染方面.我知道docxjs在HTML中的呈现方式与docx文件并不相同,所以这是一个问题...

I have a node web app that needs to convert a docx file into pdf (using client side resources only and no plugins). I've found a possible solution by converting my docx into HTML using docxjs and then HTML to PDF using jspdf (docx->HTML->PDF). This solution could make it but I encountered several issues especially with rendering. I know that docxjs doesn't keep the same rendering in HTML as the docx file so it is a problem...

所以我的问题是,您是否知道任何免费的模块/解决方案都可以直接完成这项工作而无需通过HTML(我也愿意将odt用作源代码)?如果没有,您会建议我做什么?

So my question is do you know any free module/solution that could directly do the job without going through HTML (I'm open to odt as a source as well)? If not, what would you advise me to do?

谢谢

推荐答案

您已经知道没有可立即使用的开放库.我的建议是:

As you already know there is no ready-to-use and open libs for this.. You just can't get good results with available variants. My suggesition is:

  1. 使用第三方API.就像 https://market.mashape.com/convertapi/word2pdf-1#!documentation
  2. 为此目的创建您自己的服务.如果您具备这种能力,建议您在node.js上创建一个小型服务器(我敢打赌您知道该怎么做).您可以将Libreoffice用作具有良好渲染质量的良好转换器,如下所示:

  1. Use third party API. Like https://market.mashape.com/convertapi/word2pdf-1#!documentation
  2. Create your own service for this purpose. If you have such ability, I suggest to create a small server on node.js (I bet you know how to do this). You can use Libreoffice as a good converter with good render quality like this:

libreoffice -headless -invisible -convert-to pdf {$ file_name} -outdir/www-disk/

别忘了这通常会花费很多时间,不要阻塞请求-应答流:对每个转换操作使用单独的过程.

Don't forget that this is usually takes a lot of time, do not block the request-answer flow: use separate process for each convert operation.

最后一件事.Libreoffice不是很轻巧,但是质量很好.您还可以找到著名的 unoconv 工具.

And the last thing. Libreoffice is not very lightweight but it has good quality. You can also find notable unoconv tool.

截至2019年1月,有 docx-wasm 有效在节点上,并在安装了节点的本地执行转换.专有但免费.

As of January 2019, there is docx-wasm, which works in node and performs the conversion locally where node is installed. Proprietary but freemium.

这篇关于使用JavaScript将docx/odt转换为PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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