Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Java: Obtenir le nombre de Page d’un document PDF

Java: Obtenir le nombre de Page d'un document PDF
{filelink=10506}

/***** Code de MesExemples.com *******/
/**
 * @(#)DocumentPageCountPDF.java
 *
 *
 * @author 
 *sakoba(java.mesexemples.com) @version 1.00 2013/5/29
 */
 
 
 
import java.io.FileOutputStream;
 
import com.itextpdf.text.Document;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Paragraph;
import com.itextpdf.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("c:/DocumentPageCountPDF.pdf"));
      doc.open();
 
      Paragraph p = new Paragraph("text");
 
      doc.add(p);
 
      doc.close();
      System.out.println(writer.getPageNumber());
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
 
}