Bug 61467 - Created word file using apache poi api is corrupted after adding the image to word doc.
Summary: Created word file using apache poi api is corrupted after adding the image to...
Status: NEEDINFO
Alias: None
Product: POI
Classification: Unclassified
Component: XWPF (show other bugs)
Version: 3.16-FINAL
Hardware: PC All
: P2 major (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-08-29 08:48 UTC by kiran.tl
Modified: 2018-03-22 12:32 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description kiran.tl 2017-08-29 08:48:37 UTC
Hi,

I have used apache poi 3.16 to create word document. whenever I add .tif images to word document using run.addPicture(..) provided by poi 3.16 api. When generated .doc or .docx is trying to open it throws below error message.

Error popup message - "XX.doc cannot be opened because there are problems with the contents."

Looks like word file is corrupted.

Can you please take a look and help me about this issue.

Also please let me know if you need any additional information.

Thanks in advance !
Comment 1 Dominik Stadler 2017-12-31 09:26:57 UTC
Can you provide some self-sufficient sample-code which allows to reproduce the problem?
Comment 2 chandanam1412 2018-03-22 11:42:57 UTC
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."
Comment 3 Mark Murphy 2018-03-22 12:32:35 UTC
(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?