Converting docx to pdf with pure python (on linux, without libreoffice)

The PythonAnywhere help pages offer information on working with PDF files here: https://help.pythonanywhere.com/pages/PDF Summary: PythonAnywhere has a number of Python packages for PDF manipulation installed, and one of them may do what you want. However, shelling out to abiword seems easiest to me. The shell command abiword –to=pdf filetoconvert.docx will convert the docx file to … Read more

Python-docx, how to set cell width in tables?

Short answer: set cell width individually. for cell in table.columns[0].cells: cell.width = Inches(0.5) python-docx does what you tell it to do when you set column width. The problem is that Word ignores it. Other clients, like LibreOffice, respect the column width setting. A .docx file is in XML format (hence the ‘x’ suffix in the … Read more

How to use python-docx to replace text in a Word document and save

UPDATE: There are a couple of paragraph-level functions that do a good job of this and can be found on the GitHub site for python-docx. This one will replace a regex-match with a replacement str. The replacement string will appear formatted the same as the first character of the matched string. This one will isolate … Read more