我正在尝试使用 iText 阅读 pdf。下面是我收到异常的代码片段“未找到作为文件或资源”:
public void readFromPdf(){
String content ="";
PdfReader reader = null;
try {
//String fileName is the string with the path to your .pdf file, for example resources/pdfs/preface.pdf
reader = new PdfReader("C:\\test\\demo.pdf");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int numberOfPages = reader.getNumberOfPages();
numberOfPages = numberOfPages + 1;
for (int page = 1; page < numberOfPages; page++){
try {
String content1Page = PdfTextExtractor.getTextFromPage(reader, page);
content = content + content1Page;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
谁能弄清楚出了什么问题?