Bug 55476 - [PATCH] Fixed: after XWPFRun.addPicture() Word considers the document as corrupted
Summary: [PATCH] Fixed: after XWPFRun.addPicture() Word considers the document as corr...
Status: RESOLVED WORKSFORME
Alias: None
Product: POI
Classification: Unclassified
Component: XWPF (show other bugs)
Version: 3.11-dev
Hardware: PC All
: P2 normal with 7 votes (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords: PatchAvailable
Depends on: 49765
Blocks:
  Show dependency tree
 
Reported: 2013-08-23 20:23 UTC by Dmitry Romanov
Modified: 2016-02-15 19:18 UTC (History)
1 user (show)



Attachments
the 2-lines patch to XWPFRun which solves the problem of adding images to docx document using XWPFDocument (704 bytes, text/plain)
2013-08-23 20:23 UTC, Dmitry Romanov
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Dmitry Romanov 2013-08-23 20:23:58 UTC
Created attachment 30758 [details]
the 2-lines patch to XWPFRun which solves the problem of adding images to docx document using XWPFDocument

If you try to add a picture to XWPFDocument:

XWPFDocument document = new XWPFDocument().createParagraph().createRun().addPicture(pictureIn, Document.PICTURE_TYPE_JPEG, "test.jpg", Units.toEMU(300), Units.toEMU(100));

and then will save it using:

document.write(outputStream);

Microsoft Word won't open such file saying that it is corrupted.
There is discussion which touches this issue as well in comments in:
https://issues.apache.org/bugzilla/show_bug.cgi?id=49765

In particular the root cause is mentioned here:
https://issues.apache.org/bugzilla/show_bug.cgi?id=49765#c14

I'm attaching the patch which resolves the issue.
Comment 1 Didier Fetter 2013-08-27 00:09:25 UTC
I've tested the patch (I had just made one of my own). It works fine, the pic:pic tag is not empty anymore.
Comment 2 Dmitry Romanov 2013-08-27 18:38:03 UTC
Didier,
I see you marked the bug as RESOLVED/FIXED but I can't see the change in SVN at least in the trunk
When would we expect committing the patch to SVN?
Comment 3 Didier Fetter 2013-08-27 20:48:10 UTC
Sorry, I don't exactly know how the patches are supposed to be submitted to SVN or notified to committers. In the guidelines they just say "set the subject to [PATCH] followed by a brief description", maybe this is what we should do. Please tell me if I should change the status back.
But I think this patch should be committed soon because this issue has been reported several times in forums and in this database.
Comment 4 Dominik Stadler 2013-08-28 05:28:35 UTC
reponening this issue then as it is not commited yet
Comment 5 mengxi 2014-11-21 01:29:14 UTC
我的也是这个问题
Comment 6 Dominik Stadler 2016-02-15 19:18:22 UTC
I tried, but could not reproduce this problem, adding pictures worked fine, Microsoft Word could open the document. See the unit-test added in r1730598.

Therefore I am closing this for now, if this is still does not work for you with the latest version of POI then please provide the sample code and the exact version of Microsoft Word that you are using to allow us to reproduce this.