1.在pom.xml加入依赖

<dependency>
            <groupId>org.apache.pdfbox</groupId>
            <artifactId>pdfbox</artifactId>
            <version>1.8.11</version>
        </dependency>

2.测试代码:

package api.api;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import com.lowagie.text.pdf.PdfReader;

public class PdfPageTest {
  public static void main(String[] args) throws FileNotFoundException, IOException {
    File file = new File(“d:\\PRE-CON281100007-add-1546498235473.pdf”);
    PdfReader pdfReader = new PdfReader(new FileInputStream(file));
    int pages = pdfReader.getNumberOfPages();

    System.out.println(“pdf文件的总页数为:” + pages);
  }
}
 

版权声明:本文为xiao123456789原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/xiao123456789/p/12773731.html