How to add current page number and total number of pages in Itextsharp

as the current page number and the total number of pages in the pdf file as Page: 3/10

My code is as follows

        //PdfPTable saleTable = SaleTable();
        FileStream fileStream = new FileStream(Customer + "Invoice.pdf",
        FileMode.Create,
                                               FileAccess.Write,
                                               FileShare.None);
        Document doc = new Document(PageSize.A4);

        PdfWriter writer = PdfWriter.GetInstance(doc, fileStream);
        doc.Open();

        glue = new Chunk(new VerticalPositionMark());
        _phrase1.Add(new Chunk(glue));
        _phrase1.Add(new Chunk("Page Number: "));

        _para.Add(_phrase1);
         doc.Add(_para);
+4
source share
1 answer

Getting the current page number is very simple. You have an instance PdfWriternamed writer. You can set this instance for the current page number:

int pageNo = writer.PageNumber

In Java:

int pageNo = writer.getPageNumber();

Getting the total number of pages is not possible if you cannot look into the future. When you are on page 1, iText does not know how many pages you add. Perhaps you call the method immediately Close(), in which case the total number of pages is 1. Perhaps you plan to add one hundred pages.

.

# 1: PDF

PDF . PdfStamper . ​​ Q & A:

# 2:

PdfTemplate . , Close(), .

:

.

+6

All Articles