We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Page Numbering doesn't update on multipage tables

Hello everyone.

I’m creating pdf from xml using C# .net

Page numbering works fine, as long as everything stays on its single page. But as soon as you have a table that spans multiple pages, I get the header printed on the new page, but the page number of the current page doesn’t update.

So first page is: 1/2
and second page is: 1/2, which should be 2/2

How do I set the correct page numbering?

I’m currently setting the header like the following, but see attachment testTemplate.zip (832 Bytes) for a full example

         <Header>
	  <Margin Top="20" />
	  <Table ColumnAdjustment="AutoFitToWindow">
		<Row>
		   <Cell>
			<TextFragment>
				<TextSegment></TextSegment>
			</TextFragment>
		  </Cell>
		  <Cell Alignment="3">
			<TextFragment>
			  <TextSegment>Page $p / $P</TextSegment>
			</TextFragment>
		  </Cell>
		</Row>
	  </Table>
	</Header>

@Kupferkessel,

Can you please share which Aspose.PDF version you are using on your end. I have tried to generated PDF from XML file shared by you and facing exception.

Good evening.

@Adnan.Ahmad

I tried out the uploaded xml in case I accidently uploaded some interim file, but the generation of the pdf works without an exception for me, using version 18.4

I’m generating the pdf like this:

		string resultPath = "C:\\Users\\Kupferkessel\\Desktop\\aspose.pdf";
		string pathToTemplate = "C:\\Users\\Kupferkessel\\Desktop\\testTemplate.xml";

		File.Delete(resultPath);

		string templateString = File.ReadAllText(pathToTemplate);
		SetLicense();

		Aspose.Pdf.Document pdf = new Aspose.Pdf.Document();
		using (MemoryStream xmlStream = new MemoryStream(Encoding.UTF8.GetBytes(templateString))) {
			pdf.BindXml(xmlStream);
		}
		pdf.Save(resultPath);

@Kupferkessel,

I like to inform that you are using legacy version of Aspose.PDF. Can you please try to use Aspos.PDF latest version 20.4 and also make sure that font “Arial Unicode MS” is available on your machine if not than please try to load fonts from source folder.

@Adnan.Ahmad

Sadly updating to the newest version didn’t solve the issue. The font is installed on my machine, I can use it i.e. in notepad. But just in case i removed it: testTemplate without font.zip (797 Bytes)
But it didn’t solve the issue either, as you can see here: wrong page numbering result.pdf (37.3 KB)

@Adnan.Ahmad

It seems that the issue is that the page numbering doesn’t update in the header. If i put it in the cells, it updates correctly.

In addition of having “page $p of $P” in the header, I’ve also added it to the rows, as you can see in the attached files:

Result:

  • Page numbering in header is wrong
  • Page numbering in table is right

->
Am I adding the page numbering wrongly to the header? Is the header the wrong route to add the page number to all pages?
Files:
aspose.pdf (37.4 KB)
testTemplate correct page numbers in rows.zip (809 Bytes)

@Adnan.Ahmad

I’m starting to think, that this is a bug in the Aspose.PDF framework. When I replace the header tags with footer tags, it works as expected.

aspose.pdf (37.4 KB)
testTemplate with page numbers in footers.zip (801 Bytes)

@Kupferkessel,

I have observed your issue and like to inform that I have created investigation ticket with ID PDFNET-48132 in our issue tracking system to investigate and resolve this issue as soon possible.

1 Like