How can i access the header of a document, and to insert something there only if its not the first page?
Thank you.
Document document = new Document();
document.LoadFromFile("sample.docx");
foreach (Section section in document.Sections)
{
Paragraph p = section.HeadersFooters.Header.AddParagraph();
TextRange txt= p.AppendText("HelloWorld");
txt.CharacterFormat.FontName = "Arial";
txt.CharacterFormat.FontSize = 10;
txt.CharacterFormat.Italic = true;
p.Format.HorizontalAlignment = HorizontalAlignment.Right;
}
document.SaveToFile("output.docx",FileFormat.Docx);
Document document = new Document();
document.LoadFromFile(@"..\..\sample.docx");
foreach (Section section in document.Sections)
{
section.PageSetup.DifferentFirstPageHeaderFooter = true;
}
HeaderFooter ss = document.Sections[0].HeadersFooters.Header;
HeaderFooter header = document.Sections[0].HeadersFooters.FirstPageHeader;
header.Paragraphs.Clear();
foreach (Paragraph p in ss.Paragraphs)
{
header.Paragraphs.Add(p.Clone() as Paragraph);
}
foreach (Section section in document.Sections)
{
HeaderFooter head = section.HeadersFooters.Header;
head.LinkToPrevious = false;
Paragraph p = head.AddParagraph();
TextRange txt = p.AppendText("HelloWorld");
txt.CharacterFormat.FontName = "Arial";
txt.CharacterFormat.FontSize = 10;
txt.CharacterFormat.Italic = true;
p.Format.HorizontalAlignment = HorizontalAlignment.Right;
}
document.SaveToFile("output.docx", FileFormat.Docx);
amy.zhao wrote:Dear Catalin,
Does the code in our last post solve your issue?
Please give us a feedback on this issue at your early convenience. Thank you!
If you have any issue, please tell us.
Best Regards,
Amy
E-iceblue support team