Convert docx / odt to PDF using JavaScript

I have a node web application that needs to convert a docx file to pdf (using only client-side resources and without plugins). I found a possible solution by converting my docx to HTML using docxjs and then HTML to PDF using jspdf (docx-> HTML-> PDF). This solution can do it, but I ran into a few problems, especially with rendering. I know that docxjs does not save the same rendering in HTML as the docx file, so the problem is ...

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

thanks

+7
source share
2 answers

As you already know, there are no ready-to-use and open libraries for this .. You simply cannot get good results with the available options. My suggestion:

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

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

    Do not forget that this usually takes a lot of time, do not block the flow of request-response: use a separate process for each conversion operation.

    And the last one. Libreoffice is not very light, but is of good quality. You can also find the famous unoconv tool.

As of January 2019, there is docx-wasm that runs on the node and performs the conversion locally where the node is installed. Branded but freemium.

+7
source

It seems that even after three years ncohen did not find the answer. It was also unclear whether this should be a free (as in dollars) decision.

Initial requirements were:

using only resources on the client side and without plugins

Do you mean that you do not want server-side conversion? Well, I would like my app to be completely standalone.

Since all the other answers / comments suggested only server-side component solutions, which, as the author clearly indicated, were not what they wanted, here is the suggested answer.

The company I work with for several years now has this solution, which can completely convert DOCX files (not yet odt) to PDF in a browser, without the need for a server component. Currently used asm.js / PNaCl / WASM, depending on the browser used.

https://www.pdftron.com/samples/web/samples/viewing/viewing/

Open the office file using the demo above and you will not see the connection to the server. Everything is done on the client side. This demo also works on mobile browsers.

0
source

All Articles