package com.pdfcom;
import java.io.IOException;
import java.net.URL;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.parser.PdfTextExtractor;
/**
*
* @author hp
*读取pdf指定内容
*/
public class TestAll {
public static void main(String[] args) throws IOException {
URL url=new URL("file:/C:\\Users\\hp\\Desktop\\新建文件夹 (2)\\国网京峡ECI光传输系统500kV保北站XDM1000设备停运三措一案.pdf");
readPdf(url);//直接读全PDF面
}
public static void readPdf(URL url){
String pageContent = "";
try {
PdfReader reader = new PdfReader(url);
int pageNum = reader.getNumberOfPages();
for(int i=1;i<=pageNum;i++){
pageContent += PdfTextExtractor.getTextFromPage(reader, i);//读取第i页的文档内容
}
System.out.println(pageContent);
} catch (Exception e) {
e.printStackTrace();
}finally{
}
}
}