0

I'm developing an Electron app and would like the end-users to be able to import a Word document and convert it to a PDF. Is there a way to do this via the command-line with MS Word on Windows and macOS?

I've found solutions that covert using LibreOffice or do doc -> HTML -> pdf such as docx-pdf style conversion. Of course there are API solutions but this is a no-go due to sensitive documents.

The requirement is to convert without a change of formatting, so the thinking is using MS Word to covert would minimise chances of changes (unlike docx-pdf) but also something the end-users are more likely to have installed (LibreOffice is very niche in this sector).

Thanks.

WolfieZero
  • 377
  • 3
  • 16

2 Answers2

1

You can use the docx2pdf tool to convert a docx file to pdf retaining all formatting. It works on macOS and Windows and requires Microsoft Word to be installed.

pip install docx2pdf
docx2pdf input.docx output.pdf
docx2pdf --help

If you don't want the python dependency, you can see the JXA (AppleScript for javascript) code that can be directly run on macOS with no dependencies. It also uses win32com on windows to directly talk to Microsoft Word.

Disclaimer: I wrote the docx2pdf to pdf tool. https://github.com/AlJohri/docx2pdf/

Al Johri
  • 1,729
  • 22
  • 23
  • Al Johri, I'm trying to use your module but it is not working for me. Could you check [my question](https://stackoverflow.com/questions/62636726/why-is-the-docx2pdf-module-not-converting-docx-to-pdf-in-my-python-script-mac-os) to see whether you know what I should change for it to work? Thanks. – Jem Jun 29 '20 at 15:44
-1

If you want to generate Microsoft word/excel/PowerPoint document dynamically . Do check https://www.npmjs.com/package/officegen

Shrinath
  • 364
  • 1
  • 13
  • The solution I'm looking for needs to generate a PDF from a Word document, that package only looks to create an Office document from input (which is sort of the opposite of what I'm looking for). – WolfieZero Feb 27 '19 at 10:28