python-openxml / python-docx

Create and modify Word documents with Python
MIT License
4.52k stars 1.11k forks source link

find and replace images with text #1170

Open arth17singh opened 1 year ago

arth17singh commented 1 year ago

I have a document with a table which contains text and images both ( one cell can contain both text and images). I need to find a way to find and replace the images in the document with specific text(for example link of the image instead of the actual image) so that I can cover this table to a database and re-render the images through the link. I need to replace the images with the text so that while rendering them again I should get the exact location of the images again. How should this be done using python-docx, as I only able to extract the images using their rid tags but not able to replace them with another text in the original document.

scanny commented 1 year ago

This is not currently an available feature. You'd have to do surgery on the run XML yourself.

But it's an interesting use case. I'm going to tag it for consideration next time we're in looking at image support, which we might be before long to extract images for OCR purposes.