pdf文件中的页数 [英] no.of pages in pdf file

查看:74
本文介绍了pdf文件中的页数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用pdfbox"阅读 pdf 文件;我没有得到 pdf 文档中的总页数..我不知道为什么会这样.

I am reading a pdf file using "pdfbox";I am not getting the total number of pages in the pdf document..I don't know why this is happening.

try {
    parser = new PDFParser(new FileInputStream(file));
    parser.parse();
    cosDoc = parser.getDocument();
    pdfStripper = new PDFTextStripper();
    pdDoc = new PDDocument(cosDoc);

    for (int i = 1; i <= pdDoc.getDocumentCatalog().getAllPages().size(); i++) {
        pdfStripper.setStartPage(i);
        pdfStripper.setEndPage(i);
        parsedText = pdfStripper.getText(pdDoc);
        if(i==11)
        System.out.println(parsedText/*.replaceAll("[^A-Za-z0-9. ]+", "")*/);
    }
} catch (Exception e) {
    e.printStackTrace();
    try {
        if (cosDoc != null)
            cosDoc.close();
        if (pdDoc != null)
            pdDoc.close();
    } catch (Exception e1) {
        e.printStackTrace();
    }

}

pdDoc.getDocumentCatalog().getAllPages().size();没有给出页数..有人可以帮我吗...

pdDoc.getDocumentCatalog().getAllPages().size(); is not giving the no.of pages..can someone help me pls...

推荐答案

您可能正在寻找的是这种方法

What you are probably looking for is this method

pdDoc.getNumberofPages();

https://pdfbox.apache.org/docs/2.0.0-SNAPSHOT/javadocs/org/apache/pdfbox/pdmodel/PDDocument.html#getNumberOfPages()

这篇关于pdf文件中的页数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆