We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Picture in header on the second page

Hi there,

I’m having a problem using headers/footers in Words for Java.
While the header on the 1st page renders as it should, the one on the 2nd page loses it’s image (the image lands in the footer as seen in the attachment).

I have tried tinkering with many options to no avail.

Is there a setting I am missing?

Here’s part of the code I am using:

renderHeader()

pageSetup.setDifferentFirstPageHeaderFooter(false);
pageSetup.setHeaderDistance(50);

                <br><br>builder.moveToHeaderFooter(com.aspose.words.HeaderFooterType.HEADER_PRIMARY);
                builder.getParagraphFormat().setAlignment(ParagraphAlignment.LEFT);
                setFontPreferences("Tahoma", 14F, true, false, Color.BLACK);
                <br><br>builder.write(header.getName());<br><br>String imageFileName = logosPath + header.getLogoFileName();
                builder.insertImage(<br>     imageFileName, <br>     RelativeHorizontalPosition.PAGE, <br>     380, <br>     RelativeVerticalPosition.INSIDE_MARGIN, <br>     32, <br>     header.getLogoWidth(), <br>     header.getLogoHeight(), <br>     WrapType.THROUGH);

                <br><br>Shape shape = new Shape(doc, ShapeType.LINE);
                <br>shape.setWidth(pageSetup.getPageWidth() - <br>     (pageSetup.getLeftMargin() + pageSetup.getRightMargin()));
                <br>shape.setTop(25);
                <br>shape.setHorizontalAlignment(HorizontalAlignment.CENTER);
                <br><br>builder.insertNode(shape);


builder.insertBreak(BreakType.LINE_BREAK);

                <br><br>renderFooter();</code><br><br><i>renderFooter()



builder.moveToHeaderFooter(com.aspose.words.HeaderFooterType.FOOTER_PRIMARY);
builder.insertBreak(BreakType.LINE_BREAK);
builder.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);


setFontPreferences(“Tahoma”, 10F, false, false, Color.BLACK);

builder.writeln(“TEXT, " + getDateTimeNow());
builder.insertBreak(BreakType.LINE_BREAK);
builder.insertBreak(BreakType.LINE_BREAK);
builder.insertBreak(BreakType.LINE_BREAK);


Shape shape = new Shape(doc, ShapeType.LINE);

shape.setWidth(180);

shape.setTop(35);

shape.setHorizontalAlignment(HorizontalAlignment.CENTER);
builder.insertNode(shape);


builder.writeln(“MORE TEXT”);

builder.writeln(”(ANOTHER TEXT)");

                <br>builder.startTable();
                <br>builder.getCellFormat().clearFormatting();
                builder.getCellFormat().getBorders().clearFormatting();


builder.insertCell();
builder.getCellFormat().setPreferredWidth(PreferredWidth.fromPercent(100));
builder.getCurrentParagraph().getParagraphFormat().setAlignment(ParagraphAlignment.RIGHT);


setFontPreferences(“Tahoma”, 6F, false, true, Color.BLACK);
builder.write(“Seite “);

builder.insertField(“PAGE”, “”);

builder.write(”/”);

builder.insertField(“NUMPAGES”, “”);

                <br><br>builder.endRow();
                <br>builder.endTable();
                <br>builder.moveToDocumentStart();</code><code></code>

Hi Lucian,

Thanks for your inquiry. It would be great if you please share following detail for investigation purposes.


  • Please attach your input Word document.
  • Please
    share the runnable simple Java application that demonstrates the code (Aspose.Words code) you used to generate
    your output document.
  • Please attach the output document that shows the undesired behavior.
  • Please share to which file format you are saving your final output document.

As soon as you get these pieces of information to
us we’ll start our investigation into your issue.

Hi Tahir,

nerver mind the question.
I found the answer to as easy as setting the image relativity to PAGE.

RelativeVerticalPosition.INSIDE_MARGIN =>
RelativeVerticalPosition.PAGE

Thanks for your time.
Lucian.

Edit: please close the post.

Hi Lucian,

Thanks for your feedback. It is nice to hear from you that you have found the solution of your issue. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.