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>