DocumentPageCountPDF.java Source code

Java tutorial

Introduction

Here is the source code for DocumentPageCountPDF.java

Source

import java.io.FileOutputStream;

import com.lowagie.text.Document;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;

public class DocumentPageCountPDF {
    public static void main(String args[]) {
        try {
            Document doc = new Document(PageSize.A4, 50, 50, 100, 72);
            PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream("DocumentPageCountPDF.pdf"));
            doc.open();

            Paragraph p = new Paragraph("text");

            doc.add(p);

            doc.close();
            System.out.println(writer.getPageNumber());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}