Reputation: 198
I've spent much time to no avail on this issue. My PDF pages are automatically numbered 'Page 1 of 0' when creating a PDF as follows:
using (MemoryStream ms = new MemoryStream())
using (Document document = new Document(PageSize.A4, 10, 10, 25, 25))
using (PdfWriter writer = PdfWriter.GetInstance(document, ms))
{
writer.PageEvent = new TextEvents();
document.Open();
document.NewPage();
document.Add(new Phrase("Hello World!"));
document.Close();
writer.Close();
var docout = ms.ToArray();
ms.Close();
return docout;
}
How do I stop this behaviour? I do not want a page numberer.
Upvotes: 1
Views: 924
Reputation: 58
To add to the above answer, TextEvents()
should be extending PdfPageEventHelper
which has an onEndPage()
method where you will find the code that adds page x of n.
Upvotes: 0
Reputation: 95918
In this line
writer.PageEvent = new TextEvents();
you tell itext to send page events to an instance of your own TextEvents
class. As no other part of the code you show adds page numbers, it must be this class of yours that does.
You can test this by removing the code line quoted above.
Beware: probably that TextEvents
class does something else, too, probably something you want. Instead of completely removing that line above, therefore, you might eventually have to analyse your TextEvents
class and only remove the unwanted behaviour.
Upvotes: 2