Summary: | Created word file using apache poi api is corrupted after adding the image to word doc. | ||
---|---|---|---|
Product: | POI | Reporter: | kiran.tl |
Component: | XWPF | Assignee: | POI Developers List <dev> |
Status: | NEEDINFO --- | ||
Severity: | major | CC: | kiran.tl |
Priority: | P2 | ||
Version: | 3.16-FINAL | ||
Target Milestone: | --- | ||
Hardware: | PC | ||
OS: | All |
Description
kiran.tl
2017-08-29 08:48:37 UTC
Can you provide some self-sufficient sample-code which allows to reproduce the problem? xWPFParagraph title = doc.createParagraph(); XWPFRun run = title.createRun(); run.setText("Fig.1 A Natural Scene"); run.setBold(true); title.setAlignment(ParagraphAlignment.CENTER); String imgFile = "C:\\WordGenerator\\Congisoft_Logo.png"; FileInputStream is = new FileInputStream(imgFile); run.addBreak(); run.addPicture(is, XWPFDocument.PICTURE_TYPE_JPEG, imgFile, Units.toEMU(200), Units.toEMU(200)); // 200x200 pixels is.close(); FileOutputStream fos = new FileOutputStream("F:\\test4.docx"); doc.write(fos); fos.flush(); fos.close(); /// Whole i am trying to open my word document. Error popup message - ".doc cannot be opened because there are problems with the contents." (In reply to chandanam1412 from comment #2) > xWPFParagraph title = doc.createParagraph(); > XWPFRun run = title.createRun(); > run.setText("Fig.1 A Natural Scene"); > run.setBold(true); > title.setAlignment(ParagraphAlignment.CENTER); > > String imgFile = "C:\\WordGenerator\\Congisoft_Logo.png"; > FileInputStream is = new FileInputStream(imgFile); > run.addBreak(); > run.addPicture(is, XWPFDocument.PICTURE_TYPE_JPEG, imgFile, > Units.toEMU(200), Units.toEMU(200)); // 200x200 pixels > is.close(); > > FileOutputStream fos = new FileOutputStream("F:\\test4.docx"); > doc.write(fos); > fos.flush(); > fos.close(); > > > /// > Whole i am trying to open my word document. > Error popup message - ".doc cannot be opened because there are problems with > the contents." So you are wondering why adding a PNG, but telling POI that it is a JPEG produces a corrupted document? |