Working with picture in AlternateContent tag

Viewed 24

I need to move an element from one document to another by using python-docx. The element is AlternateContent which represents shapes and figures in Office Word, the issue here is that one of the elements contains an image like this:

<AlternateContent>
    <Choice Requires="wpc">
        <drawing>
            <inline distT="0" distB="0" distL="0" distR="0" wp14:anchorId="0DCE320C" wp14:editId="0DCE320D">
                <extent cx="5826587" cy="2494357" />
                <effectExtent l="0" t="0" r="0" b="1270" />
                <docPr id="1108" name="Zeichenbereich 5" />
                <cNvGraphicFramePr>
                    <graphicFrameLocks xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" noChangeAspect="1" />
                </cNvGraphicFramePr>
                <graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
                    <graphicData uri="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas">
                        <wpc>
                            <pic xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture">
                                <nvPicPr>
                                    <cNvPr id="687" name="Picture 28" />
                                    <cNvPicPr>
                                        <picLocks noChangeAspect="1" noChangeArrowheads="1" />
                                    </cNvPicPr>
                                </nvPicPr>
                                <blipFill>
                                    <blip r:embed="rId20">
                                        <extLst>
                                            <ext uri="{28A0092B-C50C-407E-A947-70E740481C1C}">
                                                <useLocalDpi xmlns:a14="http://schemas.microsoft.com/office/drawing/2010/main" val="0" />
                                            </ext>
                                        </extLst>
                                    </blip>
                                    <srcRect />
                                    <stretch>
                                        <fillRect />
                                    </stretch>
                                </blipFill>
                            </pic>
                        </wpc>
                    </graphicData>
                </graphic>
            </inline>
        </drawing>
    </Choice>
</AlternateContent>

What I did is extract the image by getting its rid from r:embed and then save it to the disk, after I re-add the image using add_picture() from the Run class, sadly this process cannot be achieved because from above example the <pic> tag is not included in a run.
So my question is how I can save the element AlternateContent into python object then re-add it to a Word document?
Thanks in advance!

0 Answers
Related