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

Free Support Forum - aspose.com

Not able to see the image in the header

Hi,

I am trying to add the image to header but I am not able to see it in the output doc file.

The size of the result file increases but the image is invisible.

Can you guide me on that?

Also please tell me that do I need to add any type of field in my template.

Currently my template is not having the header inserted from Word.

Do I need to add that or the code is enough to make things working?

I am copying few LOC here.

----------------------------------------------------------------------------

DocumentBuilder builder = new DocumentBuilder(doc);

// Set the header

Section currentSection = builder.getCurrentSection();

PageSetup pageSetup = currentSection.getPageSetup();

pageSetup.setHeaderDistance(20);

builder.moveToHeaderFooter(HeaderFooterType.HEADER_FIRST);

Shape shape = builder.insertImage(imageUrl);

shape.setWidth(150);

shape.setHeight(300);

builder.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);

-------------------------------------------------------------------------------------------------------------------------------------------

Let me know what I am doing wrong.

I hope its not because I am using Evaluation version.

Thanks

Bhoomica

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. No, this is not a restriction of evaluation version of Aspose.Words. You just missed to set DifferentFirstPageHeaderFooter property. That’s why you never see first page header. Please try using the following code:

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

String imageUrl = "C:\\Temp\\test.jpg";

// Set the header

PageSetup pageSetup = builder.getPageSetup();

pageSetup.setDifferentFirstPageHeaderFooter(true);

pageSetup.setHeaderDistance(20);

builder.moveToHeaderFooter(HeaderFooterType.HEADER_FIRST);

builder.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);

Shape shape = builder.insertImage(imageUrl);

shape.setWidth(150);

shape.setHeight(300);

doc.save("C:\\temp\\out.doc");

Also please follow the link to learn how to insert Header/Footer.

http://www.aspose.com/documentation/file-format-components/aspose.words-for-.net-and-java/moving-to-a-headerfooter.html

Hope this helps.

Best regards.