pythonimagems-wordpython-docx

How to change image position and text wrapping using python-docx?


After adding the image using add_method(), I want to change the image position and text wrapping properties.

I want to change the text-wrapping: in front of text

I want to change the properties as

horizontal

alignment : right , relative to : margin

vertical

absolute position: 2.15 cm , below: Page

This is how I change it manually in word, but I want to do it using python-docx

Is there any way to get it done?


Solution

  • The short answer is "No."

    There are two ways images can be placed in Word, inline images and floating images.

    An inline image is placed in a run and is essentially treated as a big character. The height of the line it appears on is adjusted upward to fit the image and the paragraph it is in flows between pages depending on the text before it, just like any other paragraph.

    A floating image lies on the drawing layer, like a clear plastic sheet above the document layer where the text lives. It is given an absolute position and in general does not flow with the text (although it can be anchored to part of the text). Text can be set to wrap around the image, wherever it ends up on the page.

    python-docx currently only supports inline images. There is no existing API support for floating images (and the text wrapping they allow).