Footer lost in pdf when saved unless saved in doc format first

Hello Aspose,

we add an image in jpeg format to a document’s footer which works perfectly fine when saving in Word’s doc format. When saving the same document in pdf format, the image in the footer is missing. After saving in doc format and rereading the document, saving in pdf works too.

That’s how we do it:

if (config.getAddLogo())
{
    applyWordFooter(doc);
    // workaround: without saving and rereading in doc format, the footer gets lost for saving in pdf format.
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    doc.save(baos, SaveFormat.DOC);
    doc = new Document(new ByteArrayInputStream(baos.toByteArray()));
}

PdfSaveOptions options = new PdfSaveOptions();
options.setPageCount(doc.getPageCount());
ByteArrayOutputStream baos = new ByteArrayOutputStream();

doc.save(baos, options);

==============================================================

private void applyWordFooter(Document doc) throws Exception {
     DocumentBuilder builder = new DocumentBuilder(doc);

     builder.moveToHeaderFooter(HeaderFooterType.FOOTER_PRIMARY);
     Shape shape = builder.insertImage(FOOTER_CONTENT);
     shape.setWrapType(WrapType.NONE);
     shape.setBehindText(true);
     shape.setHorizontalAlignment(HorizontalAlignment.CENTER);
}

Thanks for your help!

cfodev

Hi Otto

Thanks for your inquiry. I think, in this case, calling Document.updatePageLayout method before saving the document to PDF will help. For more information, please read the FAQs mentioned in the following link:
https://docs.aspose.com/words/java/insert-and-append-documents/

Best regards,