Search code examples
python-3.xdocxpython-docx

Python-docx add_picture size won't print as shown on screen


I have wrote a program for work that creates a report in MS Word using python-docx. I am adding pictures, which I size to my liking. Everything looks great...until I print. The pictures I added using python-docx have "un-sized" themselves. My document looks great on the screen and even in the print preview. This problem can also be seen if printing to PDF. Using the demo from python-docx, which exhibits the problem as well...

from docx import Document
from docx.shared import Inches

document = Document()
document.add_picture('picture.jpg', width=Inches(4.9))
document.save('demo.docx')

Solution

  • There is a related issue here in the python-docx issue list: https://github.com/python-openxml/python-docx/issues/94

    If you'll add your symptoms there we'll see if we can get it fixed up.

    Are you using actual Microsoft Word or are you using LibreOffice?

    UPDATE:

    This issue was remedied in the v0.8.2 release of python-docx on Feb 16 2015.