Header and Footer missing and page empty?

Hello, below are my scenarios?

Q1: I am successfully able to generate the report, I have designed the header and footer in the xml but header and footer is only appearing on the first page not repeating on the rest of the pages, can you plz guide me what to do or what I am missing?

Q2: When ever I am generating the repot it is always keeping first page empty, why? I am using DataTable of .NET to populate the data, please need guidence as well. thankx

Khurram

Hi,

Thank you for considering Aspose.

  1. HeaderFooter class has some properties like IsFirstPageOnly, IsSubsequentPagesOnly and IsLastPageOnly. Using these properties, we can control the display of header or footer on first, last or subsequent pages of the PDF document. I think you might be setting the IsFirstPageOnly property to true. Bydefault it is false, please set it to false. For example:
  1. Can you please share you code and XML file that could produce this problem. Then we will be able to investigate this issue.

If you need more help, please do let us know.

Thanks.

Adeel Ahmad
Support Developer
Aspose Changsha Team

Hello, below i have pasted the code, hope this will give you idea, you will find 2 functions and xml I am using to generate the file, but dont know why always the first page is getting empty and populating the data from the 2nd page, by the way the first page is always having the header I have designed, but not appearing on the rest of the pages, no dear I am not setting any property which avoid the header on the rest of the pages, but even though the headers are only appearing only on the first page.

Thanks and best regards

public void GenerateStatement(DataTable table, string filename)

{

pdf = new Aspose.Pdf.Pdf();

pdf.IsTruetypeFontMapCached = false;

pdf.BindXML(ConfigurationManager.AppSettings["AppRootPath"].ToString() +

ConfigurationManager.AppSettings["FPTemplateEn"].ToString(), null);

Section section1 = pdf.Sections["section1"];

Section TransactionSection = pdf.Sections["TransSection"];

Segment customerName = pdf.GetObjectByID("SegmentCustomerName") as Segment;

Segment customerAddress = pdf.GetObjectByID("SegmentCustomerAddress") as Segment;

Segment fromToDate = pdf.GetObjectByID("SegmentFromTo") as Segment;

StringBuilder _customerAddress = new StringBuilder();

StringBuilder _fromToDate = new StringBuilder();

// Label 3

_fromToDate.Append("From : " + _startDate + " TO : " + _endDate + " STATEMENT DATE : " + DateTime.Now.ToString() + " PAGE : 1 ");

//Label 3

_accountInfo.Append("ACCOUNT TITLE: " + _accountTitle+ "\n");

_accountInfo.Append("BRANCH: " + _branch + "\n");

customerAddress.Content = customerAddress.Content.Replace(customerAddress.Content, _customerAddress.ToString());

fromToDate.Content = fromToDate.Content.Replace(fromToDate.Content, _fromToDate.ToString());

foreach (DataRow dataRow in table.Rows)

{

AddRow(dataRow, TransactionSection, pdfTable);

}

pdf.Save(@"c:\temp\report.pdf");

}

private void AddRow(DataRow dataRow, Section section, Aspose.Pdf.Table pdftable)

{

Table newTable = new Table();

section.Paragraphs.Add(newTable);

newTable.IsBroken = false;

newTable.DefaultCellTextInfo.FontSize = 10;

newTable.DefaultCellTextInfo.FontName = "Courier";

newTable.ColumnWidths = "70 70 200 70 70 70";

newTable.Border = new BorderInfo();

Aspose.Pdf.Row row1DetailTable = newTable.Rows.Add();

row1DetailTable.Cells.Add(dataRow["Col1"].ToString());

row1DetailTable.Cells.Add(dataRow["Col2"].ToString());

row1DetailTable.Cells.Add(dataRow["Col3"].ToString());

row1DetailTable.Cells.Add(dataRow["Col4"].ToString());

row1DetailTable.Cells.Add(dataRow["Col5"].ToString());

}

XML

====

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

<Pdf xmlns="Aspose.Pdf" Title="Invoice" Author="Khurram Shahzad" DestinationType="FitWidth">

<Section PageMarginLeft='10' PageMarginRight='80' PageMarginTop='140' ID='section1' LineWidth="0.2" PageWidth="20cm">

<Header IsFirstPageOnly="false">

<Table ColumnWidths="120 120 120 50 120" DefaultCellPaddingBottom="0"

DefaultCellPaddingLeft="35" DefaultCellPaddingRight="0" DefaultCellPaddingTop="0" >

<Border>

<All LineWidth="0"></All>

</Border>

<DefaultCellBorder>

<All LineWidth="0"></All>

</DefaultCellBorder>

<Row>

<Cell></Cell>

<Cell></Cell>

<Cell></Cell>

<Cell></Cell>

<Cell>

<Image ID="logo" ImageScale="0.60" File="D:\Data\Templates\invoice.jpg"></Image>

</Cell>

</Row>

</Table>

<Table ColumnWidths="120 120 60 40 200" DefaultCellPaddingBottom="0"

DefaultCellPaddingLeft="35" DefaultCellPaddingRight="0" DefaultCellPaddingTop="0" >

<Border>

<All LineWidth="0"></All>

</Border>

<DefaultCellBorder>

<All LineWidth="0"></All>

</DefaultCellBorder>

<Row>

<Cell></Cell>

<Cell></Cell>

<Cell></Cell>

<Cell></Cell>

<Cell PaddingLeft="0" >

<Text ID="TextCustomerName" FontName="Courier" FontSize="10">

<Segment ID="SegmentCustomerName" >CustomerName</Segment>

<Segment ID="SegmentCustomerAddress">Saudi Arabia</Segment>

</Text>

</Cell>

</Row>

</Table>

<Table ColumnWidths="530" DefaultCellPaddingBottom="0" Alignment="Left" BackgroundColor="rgb 223 255 255"

DefaultCellPaddingLeft="35" DefaultCellPaddingRight="0" DefaultCellPaddingTop="0">

<Border>

<All LineWidth="0"></All>

</Border>

<DefaultCellBorder>

<All LineWidth="0"></All>

</DefaultCellBorder>

<Row>

<Cell PaddingLeft="0" >

<Text ID="TextFromTo" FontName="CourierBold" FontSize="10">

<Segment ID="SegmentFromTo" >FromTo</Segment>

</Text>

</Cell>

</Row>

</Table>

<Table ColumnWidths="530" DefaultCellPaddingBottom="0" Alignment="Left"

DefaultCellPaddingLeft="35" DefaultCellPaddingRight="0" DefaultCellPaddingTop="0">

<Border>

<All LineWidth="0"></All>

</Border>

<DefaultCellBorder>

<All LineWidth="0"></All>

</DefaultCellBorder>

<Row>

<Cell PaddingLeft="0" >

<Text ID="TextAccountNumber" FontName="CourierBold" FontSize="8" IsTrueTypeFontBold="true">

<Segment ID="SegmentAccountNumber">Account Number</Segment>

</Text>

</Cell>

</Row>

</Table>

<Table ColumnWidths="70 70 200 70 70 70" DefaultCellPaddingBottom="0" Alignment="Left" BackgroundColor="rgb 223 255 255"

DefaultCellPaddingLeft="35" DefaultCellPaddingRight="0" DefaultCellPaddingTop="0">

<Border>

<All LineWidth="0"></All>

</Border>

<DefaultCellBorder>

<All LineWidth="0"></All>

</DefaultCellBorder>

<Row>

<Cell PaddingLeft="0" >

<Text ID="TextTrandDate" FontName="Courier" FontSize="10">

<Segment ID="SegmentTrandDate" >Date</Segment>

</Text>

</Cell>

<Cell PaddingLeft="0" >

<Text ID="TextValueDate" FontName="Courier" FontSize="10">

<Segment ID="SegmentValueDate" >Value</Segment>

</Text>

</Cell>

<Cell PaddingLeft="0" >

<Text ID="TextTranDescription" FontName="Courier" FontSize="10">

<Segment ID="SegmentTranDescription" >Description</Segment>

</Text>

</Cell>

<Cell PaddingLeft="0" >

<Text ID="TextTranType" FontName="Courier" FontSize="10">

<Segment ID="SegmentTranTypet" >Debit</Segment>

</Text>

</Cell>

<Cell PaddingLeft="0" >

<Text ID="TextTranEvent" FontName="Courier" FontSize="10">

<Segment ID="SegmentTranEvent" >Credit</Segment>

</Text>

</Cell>

<Cell PaddingLeft="0" >

<Text ID="TextBal" FontName="Courier" FontSize="10">

<Segment ID="SegmentBal" >Balance</Segment>

</Text>

</Cell>

</Row>

</Table>

</Header>

</Section>

<Section PageMarginLeft='10' PageMarginRight='80' PageMarginTop='140' LineWidth="0.2" PageWidth="20cm" ID="TransSection"></Section>

</Pdf>

Hi,

I have checked your code and XML file and found the problems:

  1. Table is starting from the second page because you have added two sections in it and ByDefault section starts with a new page. Hence just change your XML and set isNewPage=‘false’ like :
  1. About the secong problem of Header not showing on all the pages, so the reason is same Header and Footers are part of the section, they are shown with in the section and as you are having two sections and second section didn’t have Header and Footer hence you won’t see in the next page any header. So, for that I think you should use one Section and use the API to set the Header Row of the table.

If you need more help, please do let us know.

Thanks.

Adeel Ahmad
Support Developer
Aspose Changsha Team