-
Notifications
You must be signed in to change notification settings - Fork 769
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Insert images into document with shapes #458
base: trunk
Are you sure you want to change the base?
Insert images into document with shapes #458
Conversation
- given a document with 0 - 10 shapes - inserting 0 to 10 images - works for inserting 0 to 1 images - fails for more than 1 image - no matter the amount of shapes
Co-authored-by: Christina Eckleder <[email protected]>
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.
|
See also https://stackoverflow.com/questions/68074154/are-there-mcalternatecontent-and-mcfallback-support-in-poi-xwpf-parser and https://stackoverflow.com/questions/46802369/replace-text-in-text-box-of-docx-by-using-apache-poi/46894499#46894499 for related discussions about "AlternateContent" |
@centic9 , thanks for replying so fast. We're testing the workaround in our project. Another observation: "unable to open document" in Word only seems to happen when the shape is part of the footer. Word seems to be able to handle shapes in the document body better 🤔. |
- also use footer paragraphs in workaround - still produces broken documents :( Co-authored-by: Christina Eckleder <[email protected]>
Hi @centic9 , we've done some more research and are using documents with shapes in the footer now. Applying the workaround as you posted it didn't fix the documents. We also tried to add the footer paragraphs to the list of paragraphs the workaround iterates over. That didn't help either. We also discarded our test assertions as the |
Ok, as said I am not sure if this will even make it work, but two things I see which might be off:
Otherwise you will need to narrow down the problem as much as possible, both by making the document as simple a possible and the changes to the document as well. Unfortunately I cannot help much because I only have the online-version of Microsoft Word and this one seems to be able to load the document just fine. |
- doesn't fix "cannot load document" error
- still not improving
Thanks again for helping. I'm now running the workaround directly after loading the document. I've also changed the XPath to I'll keep digging. |
Dear POI crew,
thank you for your work on POI. We might have found a bug that occurs when inserting images into Word documents that already contain shapes. There seems to be some kind of collision between the shapes' and the images' IDs. The problem only seems to occur after a certain amount of shapes is already present in the document.
POI seems to be able to open those documents just fine. However, when opening them in Word, we get the "do you want to recover this document" dialog.
We wrote a test that should illustrate the problem but we don't know how to fix it.