Free Support Forum - aspose.com

Creating header with aspose.words after a mail merge

Hi ,

I need to add a header to my doc(aspose.word) . Below is my code : But this doesnt work ..No header is created :( I need the same header for all the pages

Dim st As FileStream = New FileStream(FilePath & DocumentFile, FileMode.Open)

Dim doc As Aspose.Words.Document = New Aspose.Words.Document(st)

doc.MailMerge.Execute(table)

Dim builder As DocumentBuilder = New DocumentBuilder(doc)

Dim currentSection As Aspose.Words.Section = builder.CurrentSection

Dim pageSetup As Aspose.Words.PageSetup = currentSection.PageSetup

pageSetup.DifferentFirstPageHeaderFooter = False

pageSetup.HeaderDistance = 20

builder.PageSetup.OddAndEvenPagesHeaderFooter = False

builder.MoveToHeaderFooter(Aspose.Words.HeaderFooterType.HeaderEven)

builder.ParagraphFormat.Alignment = ParagraphAlignment.Center

builder.Write("SAMPLE HEADER")

doc.Save("aspose.word.doc", SaveFormat.Doc, Aspose.Words.SaveType.OpenInBrowser, Response)

The above code doesn't work !!!

After this coding ,Im converting my document to a aspose.pdf(by using xml and memory stream) Will the header from the word doc be added to the pdf as well ??? or does it need a seperate coding ?

Thanks and Regards

Chithra

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

Thanks for your request. Please try using HeaderPrimary instead HeaderEven. See the following code snippet.

builder.MoveToHeaderFooter(Aspose.Words.HeaderFooterType.HeaderPrimary)

I hope this could help you.

Best regards.

yup it works … thanx :slight_smile: