iText를 사용하여 PDF 문서를 읽습니다. ArrayIndexOutOfBoundsException이 발생합니다. 이상한 점은 특정 파일 및 해당 파일의 특정 위치에서만 발생한다는 것입니다. PDF가 해당 위치에서 인코딩되는 방식과 관련이 있다고는하지만 문제가 무엇인지 파악할 수는 없습니다.iText로 PDF 문서 읽기 때때로 작동하지 않습니다
나는이 질문을 Read pdf using iText에서 보았지만이 파일의 위치를 변경하여 문제를 해결 한 것으로 보입니다. 일부 파일의 특정 위치에서 예외가 발생하면이 기능이 작동하지 않습니다. 따라서 파일 자체가 아니고 문제의 원인이되는 페이지가 예외입니다.
스택 추적은 "기본"java.lang.ArrayIndexOutOfBoundsException 스레드에서
예외입니다 : 잘못된 인덱스 : com.lowagie.text.pdf.CMapAwareDocumentFont.decodeSingleCID (알 수없는 소스) 에서 02 에서 com.lowagie.text.pdf.CMapAwareDocumentFont.decode (알 수없는 소스) (com.lowagie.text.pdf.parser.PdfContentStreamProcessor.decode) 알 수없는 소스) at com.lowagie.text.pdf.parser.PdfContentStreamProcessor $ ShowText.invoke (Unknown So (알 수없는 소스) com.lowagie.text.pdf.parser.PdfContentStreamProcessor.invokeOperator (알 수없는 소스) com.lowagie.text.pdf.parser.PdfContentStreamProcessor.processContent (알 수없는 소스) 에서 com.lowagie.text.pdf. com.pdfextractor.main.Extractor.main에서 parser.PdfTextExtractor.getTextFromPage (알 소스) (Extractor.java:61)
라인 (61)이 줄에 해당
함량 = extractor.getTextFromPage (페이지);
그래서 getTextFromPage() 메소드가 작동하지 않는다는 것이 확실합니다.
public static void main(String[] args) throws IOException{
ArrayList<String> keywords = new ArrayList<String>();
keywords.add("location");
keywords.add("Mass Spectrometry");
keywords.add("vacuole");
keywords.add("cytosol");
String directory = "C:/Ankur/Projects/PEB/Extractor/papers/";
File directoryToRead = new File(directory);
String[] sa_filesToRead = directoryToRead.list();
List<String> filesToRead = Arrays.asList(sa_filesToRead);
Iterator<String> fileItr = filesToRead.iterator();
while(fileItr.hasNext()){
String nextFile = fileItr.next();
PdfReader reader = new PdfReader(directory+nextFile);
int noPages = reader.getNumberOfPages();
PdfTextExtractor extractor = new PdfTextExtractor(reader);
String content="";
for(int page=1;page<=noPages;page++){
int index = 1;
System.out.println(page);
content = extractor.getTextFromPage(page);
}
}
}
관련 항목 : http://stackoverflow.com/questions/1753752/arrayindexoutofboundsexception-not-being-caught-and-ignored –