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

Free Support Forum - aspose.com

Header on First page only

Hi,


I am adding image in header part using Aspose. It is adding successfully on all pages. But i want it on only first page. Is there a way to implement this ?

Thanks

Hi,


I found the solution.

Thanks

Hi Shivam,


Thanks for your feedback. It is good to know that you have managed to resolve the issue at your own.

Please feel free to contact us for any query or concern, we will be more than happy to extend our support.

Best Regards,

Hi ,


I used following code to insert header .

Document doc1 = new Document(DocName);
DocumentBuilder builder = new DocumentBuilder(doc1);
builder.MoveToHeaderFooter(HeaderFooterType.HeaderFirst);
builder.InsertImage(logoimage);
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
builder.InsertImage(logoimage);
builder.MoveToHeaderFooter(HeaderFooterType.HeaderEven);
builder.InsertImage(logoimage);
doc.save(docpath);
I have removed the following line so that Header appears only on first page.

builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
builder.InsertImage(logoimage);
builder.MoveToHeaderFooter(HeaderFooterType.HeaderEven);
builder.InsertImage(logoimage);

But it worked in some documents, on another documents headers appeared on all pages.
I want header only on first page.
Thanks

Hi Shivam,


Thanks for your inquiry. Please check following code snippet, it will help you to add Header/Footer on only first page. However, if the issue persists then please share your sample input and output documents here, we will look into the issue and will guide you accordingly.

DocumentBuilder builder = new DocumentBuilder();<o:p></o:p>

PageSetup ps = builder.PageSetup;

ps.DifferentFirstPageHeaderFooter = true;

builder.MoveToHeaderFooter(HeaderFooterType.HeaderFirst);

builder.Writeln("First page header.");

builder.MoveToHeaderFooter(HeaderFooterType.FooterFirst);

builder.Writeln("First page footer.");

builder.MoveToSection(0);

builder.Writeln("Text page 1.");

builder.InsertBreak(BreakType.PageBreak);

builder.Writeln("Text page 2.");

builder.InsertBreak(BreakType.PageBreak);

builder.Writeln("Text page 3.");

builder.Document.Save("PageSetup.DifferentHeaders_Out.docx");


Best Regards,