DImuthuUpe / AndroidPdfViewer

Android view for displaying PDFs rendered with PdfiumAndroid
Apache License 2.0
8.18k stars 1.91k forks source link

how to get number of pages #1082

Open AbbasKhan786369 opened 2 years ago

AbbasKhan786369 commented 2 years ago

Is there any way that we can get all number of pages using this library?

hqyhqyhq commented 2 years ago
public static int getPdfPages(String pdfPath){
    PdfReader pdfReader = null;
    FileInputStream fileInputStream = null;
    try {
        fileInputStream = new FileInputStream(pdfPath);
        pdfReader = new PdfReader(fileInputStream);
    } catch (IOException e) {
        logger.debug(TAG + e.toString());
        e.printStackTrace();
    }

    int pages = 0;
    if(null != pdfReader){
        pages = pdfReader.getNumberOfPages();
    }else{
        logger.error(TAG + "PdfReader NULL !!!");
    }

    if(null != fileInputStream){
        try {
            fileInputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    logger.debug(TAG + "PDF 页数: " + pages);
    return pages;
}
JulesD29 commented 2 years ago

PdfReader is not used in this library ? Do we need to import PdfReader library ? How do you do that ?