Free Support Forum - aspose.com

Insert image and text on the First page of the document

I am trying to insert image and text on the first page of the document, but its inserting on all the pages.

The code i am using is

Document doc = new Document(inFileName);

DocumentBuilder builder = new DocumentBuilder(doc);

builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);

Shape shape = builder.InsertImage("D:\\stamp.bmp");

shape.RelativeHorizontalPosition = RelativeHorizontalPosition.RightMargin;

shape.HorizontalAlignment = HorizontalAlignment.Right;

shape.RelativeVerticalPosition = RelativeVerticalPosition.TopMargin;

shape.VerticalAlignment = VerticalAlignment.Top;

Aspose.Words.Font font = builder.Font;

font.Size = 14;

font.Bold = true;

font.Color = Color.Blue;

font.Name = "Arial";

builder.Write("TrnasID:123\nDate:" + DateTime.Today.ToString());

ParagraphFormat paragraphFormat = builder.ParagraphFormat;

paragraphFormat.FirstLineIndent = 8;

paragraphFormat.Alignment = ParagraphAlignment.Justify;

paragraphFormat.KeepTogether = true;

builder.Writeln("\nA whole paragraph.");

doc.Save(outFileName);

Can you please correct me, where i am wrong?

Thanks in advance.

regards

Vijay.

Hi

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

Thanks for your inquiry. If you need to insert header only on the first page, you should use HeaderFirst instead of HeaderPrimary. I think, the following article could help you to achieve what you need:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/aspose.words.pagesetup.differentfirstpageheaderfooter.html

Please let me know if you need more assistance, I will be glad to help you.

Best regards,