I am looking for a way to convert a docx to PDF using Python in Linux. So far, all I have found that works it is using Windows, is there a way to do it in Python without using libreoffice?
Asked
Active
Viewed 2,769 times
3
-
You can take a look here: https://code.activestate.com/recipes/578795-convert-microsoft-word-files-to-pdf-with-docxtopdf/ maybe that will help. Otherwise there are alternatives you can run in terminal such as Calibre https://calibre-ebook.com/about that doesn't use libreoffice, eg (after install): `ebook-convert test.docx test.pdf` – Christoffer Feb 18 '20 at 14:19
-
@abc it doesn't. Comptypes can't be used in Linux – Marisa Feb 18 '20 at 14:28
-
@Christoffer but can I use it in a Python script? – Marisa Feb 18 '20 at 14:29
-
If you really want to, you can use subprocess to call the terminal command, that's one option. Otherwise you can look at the source code since it's open source, take a look here: https://github.com/kovidgoyal/calibre and here https://manual.calibre-ebook.com/plugins.html#module-calibre.customize.conversion – Christoffer Feb 18 '20 at 15:05
1 Answers
0
You can use Aspose.Words for Python to convert documents to PDF:
import aspose.words as aw
doc = aw.Document("in.docx")
doc.save("out.pdf")

Alexey Noskov
- 1,722
- 1
- 7
- 13