Skip to content Skip to sidebar Skip to footer

How To Get The Number Of Pages Of A Pdf File In Android?

Can you help me find out the number of pages of a pdf document on Android, that will support down to at least api version 16. I am extracting document information but can't see a s

Solution 1:

Try this:

privatevoidcountPages(File pdfFile)throws IOException {
    try {

        ParcelFileDescriptorparcelFileDescriptor= ParcelFileDescriptor.open(pdfFile, ParcelFileDescriptor.MODE_READ_ONLY);
        PdfRendererpdfRenderer=null;
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
            pdfRenderer = newPdfRenderer(parcelFileDescriptor);
            totalpages = pdfRenderer.getPageCount();
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
}

Solution 2:

This solution works if you add the iTextG library to your libs folder. The library contains a class called PdfReader.

Try something like this:

PdfReaderreader=newPdfReader("Your file path");
intaa= reader.getNumberOfPages();

Post a Comment for "How To Get The Number Of Pages Of A Pdf File In Android?"