Page 1 of 1

Image not getting displayed when adding header footer

PostPosted: Wed Jul 28, 2021 3:07 pm
by sharvil
Hi,
I have added header and footer to my document. But when i download it as DOCX, the signature image that is added is not getting displayed, but if i download in DOC or PDF i can see the signature image. Can someone please help me?

Re: Image not getting displayed when adding header footer

PostPosted: Thu Jul 29, 2021 7:09 am
by jason
There isn't enough info in your post to be able to assist.

How are you adding the image? Can you attach a copy of your docx?

How are you downloading as DOC or PDF?

Re: Image not getting displayed when adding header footer

PostPosted: Fri Aug 06, 2021 4:00 pm
by sharvil
This is how i'm adding the image:
Code: Select all
private void addSignature(WordprocessingMLPackage wordMLPackage, String signOffTime, byte[] signImageArray,
                       boolean addPageBreak) throws Exception {
      P p = factory.createP();
      PPr ppr = factory.createPPr();
      ppr.setKeepNext(new BooleanDefaultTrue());
      ppr.setKeepLines(new BooleanDefaultTrue());
      p.setPPr(ppr);
      R r = factory.createR();
      Br br = factory.createBr();
//      r.getContent().add(br);
      p.getContent().add(r);

      // Adding Signature image and text
      if (Objects.nonNull(signImageArray)) {
         if (signImageArray != null && signImageArray.length > 0)
            addSignatureImage(wordMLPackage, p, signImageArray);

      }
      if (signOffTime != null) {
         addSignOffTime(p, signOffTime, addPageBreak);
      }
      wordMLPackage.getMainDocumentPart().addObject(p);
   }
        private void addSignatureImage(WordprocessingMLPackage wordMLPackage, P paragraph, byte[] bytes) throws Exception {
      BinaryPartAbstractImage imagePart = BinaryPartAbstractImage.createImagePart(wordMLPackage, bytes);

      int docPrId = 1;
      int cNvPrId = 2;
      // The parameter cx will increase/decrease size of the image
      Inline inline = imagePart.createImageInline("Sign Image", "NO IMAGE", docPrId, cNvPrId, false);

      addInlineImageToParagraph(paragraph, inline);

   }


This issue occurs only if i download as docx. I can see the image properly in DOC and PDF

Re: Image not getting displayed when adding header footer

PostPosted: Mon Aug 09, 2021 7:39 am
by jason
attach a copy of your docx?

Re: Image not getting displayed when adding header footer

PostPosted: Mon Aug 09, 2021 8:38 pm
by sharvil
Hi, sorry cant post the DOCX as it is a hospital report. The signature image is not showing up on certain versions of word, but it is showing up on other versions and on libre office.

Re: Image not getting displayed when adding header footer

PostPosted: Tue Aug 10, 2021 8:04 am
by jason
No docx = no help.
You can run it through https://github.com/plutext/docx4j/blob/ ... ingle.java to create something you may be happy to post.