0
I am trying to insert header and footer in an automatically generated docx file, the image loads but it is not visible in the file.
Just follow my code:
XWPFDocument doc = new XWPFDocument();
CTSectPr sectPr = doc.getDocument().getBody().addNewSectPr();
XWPFHeaderFooterPolicy policy = new XWPFHeaderFooterPolicy(doc,sectPr);
CTP ctpHeader = CTP.Factory.newInstance();
XWPFParagraph headerParagraph = new XWPFParagraph(ctpHeader, doc);
XWPFRun headerRun= headerParagraph.createRun();
String imgFile="ImagemCabecalho3.png";
headerRun.addPicture(new FileInputStream(imgFile),XWPFDocument.PICTURE_TYPE_PNG, imgFile, Units.toEMU(450), Units.toEMU(60));
headerParagraph.setAlignment(ParagraphAlignment.CENTER);
XWPFParagraph[] parsHeader = new XWPFParagraph[1];
parsHeader[0] = headerParagraph;
policy.createHeader(XWPFHeaderFooterPolicy.DEFAULT, parsHeader);