Bug 65487 - Problems to include image in header and footer
Summary: Problems to include image in header and footer
Status: RESOLVED INVALID
Alias: None
Product: POI
Classification: Unclassified
Component: XWPF (show other bugs)
Version: 4.1.2-FINAL
Hardware: PC All
: P2 minor (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-08-07 21:30 UTC by Antonio Amorim
Modified: 2021-09-01 12:36 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Antonio Amorim 2021-08-07 21:30:25 UTC
I have used this block of code

public void createPicture(String blipId, int id, long cx, long cy, XWPFRun run, String imageName) {

  run.setFontFamily("Elaudos Signature");
  CTInline line = run.getCTR().addNewDrawing().addNewInline();

  String picXml = "" + "<a:graphic xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\">"
    + "   <a:graphicData uri=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">"
    + "      <pic:pic xmlns:pic=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">"
   + "         <pic:nvPicPr>" + "            <pic:cNvPr id=\"" + id + "\" name=\"" + imageName + "\"/>"
   + "            <pic:cNvPicPr/>" + "         </pic:nvPicPr>" + "         <pic:blipFill>"
   + "            <a:blip r:embed=\"" + blipId
   + "\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\"/>"
   + "            <a:stretch>" + "               <a:fillRect/>" + "            </a:stretch>"
   + "         </pic:blipFill>" + "         <pic:spPr>" + "            <a:xfrm>"
   + "               <a:off x=\"0\" y=\"0\"/>" + "               <a:ext cx=\"" + cx 
   + "\" cy=\"" + cy
   + "\"/>" + "            </a:xfrm>" + "            <a:prstGeom prst=\"rect\">"
   + "               <a:avLst/>" + "            </a:prstGeom>" + "         </pic:spPr>"
   + "      </pic:pic>" + "   </a:graphicData>" + "</a:graphic>";
  XmlToken token = null;
  try {
    token = XmlToken.Factory.parse(picXml);
  } catch (XmlException xe) {
  xe.printStackTrace();
}

  line.set(token);
  line.setDistT(0);
  line.setDistB(0);
  line.setDistL(0);
  line.setDistR(0);
  CTPositiveSize2D extent = line.addNewExtent();
  extent.setCx(cx);
  extent.setCy(cy);
  CTNonVisualDrawingProps docPr = line.addNewDocPr();
  docPr.setId(id);
  docPr.setName(imageName);
  docPr.setDescr(imageName);
}

and the addPicture method but anything works 

The same code work in the body
Comment 1 Sayi 2021-09-01 07:47:19 UTC
Please use run.addPicture to add pictures, this api will work well.
Comment 2 Antonio Amorim 2021-09-01 12:35:09 UTC
Hi @Sayi

I had seen that I have to include the image in footer or header block towork well

Thanks for the tip
Comment 3 Antonio Amorim 2021-09-01 12:36:17 UTC
Resolve including the image in footer or header block