mardi 24 février 2015

Add picture to footer Apache POI

I am trying to add a picture in the footer. I create the paragraph and then create a run for add the picture but when I execute the application I have the picture box but with the text "Reading error". I tried to print the picture out of the footer and it is printed. How can I fix that?


This is my code:



CTSectPr sectPr=document.getDocument().getBody().addNewSectPr();
XWPFHeaderFooterPolicy policy=new XWPFHeaderFooterPolicy(document, sectPr);
CTP ctpFooter=CTP.Factory.newInstance();
XWPFParagraph footer=new XWPFParagraph(ctpFooter, document);
XWPFParagraph[] parsFooter=new XWPFParagraph[1];
XWPFRun fp=footer.createRun();
fp.addPicture(new FileInputStream("src/footer.png"), XWPFDocument.PICTURE_TYPE_PNG, "src/footer.png", Units.toEMU(400), Units.toEMU(60));
parsFooter[0]=footer;
policy.createFooter(XWPFHeaderFooterPolicy.DEFAULT, parsFooter);

Aucun commentaire:

Enregistrer un commentaire