ms word - Java - POI - Add a picture to the header -


i have been trying add picture new docx file using java poi header.

1) have added header, , added text (using xwpfheaderfooterpolicy).

2) have create image (using customxwpfdocument).

3) not insert image inside header area. have tried through adding picture same paragraph of header, did not work.

here function should add picture header. takes customxwpfdocument object has been created:

    private void addlogo(customxwpfdocument doc) throws invalidformatexception, ioexception, xmlexception {      string imgfile = "1.jpg";      ctp ctp = ctp.factory.newinstance();     ctr ctr = ctp.addnewr();     cttext textt = ctr.addnewt();     textt.setstringvalue( " page 1" );     xwpfparagraph codepara = new xwpfparagraph( ctp, doc );     xwpfparagraph[] newparagraphs = new xwpfparagraph[1];      //add logo     string blipid = codepara.getdocument().addpicturedata(new fileinputstream(new file(imgfile)), document.picture_type_png);     doc.createpicture(blipid, doc.getnextpicnamenumber(document.picture_type_png), 200, 200);             //     newparagraphs[0] = codepara;     ctsectpr sectpr = doc.getdocument().getbody().addnewsectpr();     xwpfheaderfooterpolicy headerfooterpolicy = new  xwpfheaderfooterpolicy( doc, sectpr );     headerfooterpolicy.createfooter( sthdrftr.default, newparagraphs );     headerfooterpolicy.createheader( sthdrftr.default, newparagraphs );  } 

here link custom class: how add picture .docx document apache poi xwpf in java

i have looked around , saw others asking it, without solution. ideas?

thanks in advance,

  • george


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -