You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by "centic9 (via GitHub)" <gi...@apache.org> on 2023/04/22 07:43:27 UTC

[GitHub] [poi] centic9 commented on pull request #458: Insert images into document with shapes

centic9 commented on PR #458:
URL: https://github.com/apache/poi/pull/458#issuecomment-1518549715

   The duplication seems to be because of the "AlternatContent" (i.e. MSs way of not changing the spec, but still adding new types of content ...).
   
   Can you try to add the following between opening the document and adding content? I am not 100% sure this is really the issue, so please verify that Microsoft Word can then read the document properly.
   
   This can also be used as workaround if it is really fixing the issue.
   
   ```
               for (XWPFParagraph paragraph : document.getParagraphs()) {
                   for (XWPFRun run : paragraph.getRuns()) {
                       XmlCursor cursor = run.getCTR().newCursor();
                       cursor.selectPath("declare namespace w='http://schemas.openxmlformats.org/wordprocessingml/2006/main' "
                               + "declare namespace mc='http://schemas.openxmlformats.org/markup-compatibility/2006' "
                               + "declare namespace wp='http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing' "
                               + ".//mc:AlternateContent/mc:Choice/w:drawing/wp:anchor/wp:docPr");
   
                       while(cursor.hasNextSelection()) {
                           cursor.toNextSelection();
                           XmlObject obj = cursor.getObject();
   
                           CTNonVisualDrawingProps docPr = CTNonVisualDrawingProps.Factory.parse(obj.xmlText());
   
                           document.getDrawingIdManager().reserve(docPr.getId());
                       }
                   }
               }
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org