Home > database >  How can I change the image layout options on python.docx?
How can I change the image layout options on python.docx?

Time:12-17

I need to creat a archive with the same pattern that other one, but i need to do this with python. In this another archive i have a image with this following configuration the image and text are alligned, but when i try to put my image with the following code

p = doc.add_paragraph()
r = p.add_run()
r.add_picture(myPath)
r.add_text(myText)

the image stays alligned just to the first line of the text, like in this image allinged just with the first line.

I see that if i go into the word and change the layout options to this With Text Wrapping, the second option everything work exactaly as i want to. But how can I chage this layout options using python?

CodePudding user response:

There is no API support for floating images in python-docx, which seems to be what you are asking about. Run.add_picture() adds a so-called "inline" picture (shape) which is treated like a single glyph (character in the run). So the line height grows to the height of the image and only that single line can abut the image.

One alternative would be to use a table with two cells, place the image in one cell and the text in the other.

  • Related