Free Support Forum - aspose.com

Problem with Multiple Sections and Additional Headers

The first page of my report has it's own header and therefore is in it's own section - Section1.

The second page and all subsequent pages have a different header and are in a new section - Section2. The HeaderFooter in Section2 has it's "IsFirstPageOnly" property set to true. It then has an Additional Header that has it's "IsSubsequentPagesOnly" property set to true.

This works fine when Section2 is the only section in the report. As soon as I combine Section1 and Section 2 into one Pdf document, the Headings no longer work as expected.

The only way I can get the two headings to work properly is if the HeaderFooter in both sections have the "IsFirstPageOnly" property set to false. This causes me to lose my desired heading for pages 3 through the end.

Thank you for any assistance.

Hi,

Thank you for considering Aspose.

I have tested your case and have not found any error. Here is the code:

[XML]

<?xml version="1.0" encoding="utf-8" ?>




header for section 1



page1 of section 1





header for first page of section 2




header for subsequent pages of section 2



page 1 of section 2


page 2 of section 2


page 3 of section 2


page 4 of section 2


[c#]

Pdf pdf = new Pdf();

Section sec1 = pdf.Sections.Add();

HeaderFooter hf1 = new HeaderFooter();
sec1.OddHeader = sec1.EvenHeader = hf1;
hf1.Paragraphs.Add(new Text("header for section 1"));

sec1.Paragraphs.Add(new Text("page1 of section 1"));

Section sec2 = pdf.Sections.Add();

HeaderFooter hf2 = new HeaderFooter();
hf2.IsFirstPageOnly = true;
sec2.OddHeader = sec2.EvenHeader = hf2;
hf2.Paragraphs.Add(new Text("header for first page of section 2"));

HeaderFooter hf3 = new HeaderFooter();
hf3.IsSubsequentPagesOnly = true;
sec2.AdditionalOddHeader = sec2.AdditionalEvenHeader = hf3;
hf3.Paragraphs.Add(new Text("header for subsequent pages of section 2"));

for(int j = 1; j <= 4; j++)
{
Text t = new Text("page " + j.ToString() + " of section 2");
t.IsFirstParagraph = true;
sec2.Paragraphs.Add(t);
}

pdf.Save("d:/test/test.pdf");

Please check my code and make sure if the result is what you want. If you still can't solve the problem, send your code to me and let me check it.

Thank you for the help.

Perhaps it is my version of Aspose.Pdf? When I run the code you provide below, Page 1 of Section 2's header is "header for subsequent pages of section 2" not "header for first page of section 2" as you would expect.

I am using Aspose.Pdf version 2.1.6.1

I will attach a GIF file which shows that the first page of section 2 has the subsequent page header.

Maybe it is a version problem. You’d better update to the latest version since I have made much improvement since 2.1.