docx4j icon indicating copy to clipboard operation
docx4j copied to clipboard

i insert img into docx file, office can't open this file

Open yang-xinfu opened this issue 1 year ago • 0 comments

docx4j version: 8.3.11 office version: 16.50

when i insert img into docx file, use office 2019 can't open this file

insert img demo:

BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(wordMLPackage, imageFile);
Inline inline = imagePart.createImageInline(UUID.randomUUID().toString(), "", l, l2, widthEmu, heightEmu, false);
drawing = RunUtils.getObjectFactory().createDrawing();
drawing.getAnchorOrInline().add(inline);

i get document.xml like :

<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
            xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
            xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"
            xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"
            xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture">
...
<w:drawing>
                    <wp:inline distT="0" distB="0" distL="0" distR="0">
                        <wp:extent cx="1104900" cy="869330"/>
                        <wp:effectExtent l="0" t="0" r="0" b="0"/>
                        <wp:docPr id="7723563636378128964" name="d00d3752-492e-4abb-bbe7-cb74cfe8ea1a" descr=""/>
                        <wp:cNvGraphicFramePr>
                            <a:graphicFrameLocks noChangeAspect="true"/>
                        </wp:cNvGraphicFramePr>
                        <a:graphic>
                            <a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture">
                                <pic:pic>
                                    <pic:nvPicPr>
                               ...
                </w:drawing>

and,i use office word create a new file,and manually insert pictures, i find document.xml like:

<a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
<a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture">
<pic:pic xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture">
....

at last,i manually modify docx4j created docx file like above ,and it can be open by office。

What can I do to make it get good result?

yang-xinfu avatar Sep 05 '24 03:09 yang-xinfu