Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python docx Lib Center Align image

I'm building a automated report program using https://python-docx.readthedocs.org/en/latest/

I'm trying to center a picture and even tried this trick that I read somewhere on google:

document.add_picture('C:\Users\Public\Pictures\Picture.jpg',height=Inches(3.44)) last_paragraph = document.paragraphs[-1] last_paragraph.style = 'centerstyle'

with no luck...

Anyone out there figured out a way to get around this?

like image 380
Ryan Avatar asked Oct 20 '14 20:10

Ryan


1 Answers

You could do something like this.

from docx import Document
from docx.enum.text import WD_ALIGN_PARAGRAPH

my_image = document.add_picture('path/to/image') 
last_paragraph = document.paragraphs[-1] 
last_paragraph.alignment = WD_ALIGN_PARAGRAPH.CENTER

I know I am probably replying to late now but maybe it helps to somebody else.

like image 62
ivan.zd Avatar answered Sep 28 '22 21:09

ivan.zd