List of usage examples for com.itextpdf.text ExceptionConverter getMessage
public String getMessage()
From source file:uk.bl.dpt.qa.flint.wrappers.iTextWrapper.java
License:Apache License
/** * Extracts text from a PDF.//from www. jav a 2s . co m * @param pFile input file * @param pOutput output file * @param pOverwrite whether or not to overwrite an existing output file * @return true if converted ok, otherwise false */ public boolean extractTextFromPDF(File pFile, File pOutput, boolean pOverwrite) { if (pOutput.exists() & (!pOverwrite)) return false; boolean ret = true; PrintWriter pw = null; PdfReader reader = null; try { pw = new PrintWriter(new FileWriter(pOutput)); reader = new PdfReader(pFile.getAbsolutePath()); PdfReaderContentParser parser = new PdfReaderContentParser(reader); TextExtractionStrategy strategy; for (int i = 0; i < reader.getNumberOfPages(); i++) { try { //page numbers start at 1 strategy = parser.processContent((i + 1), new SimpleTextExtractionStrategy()); //write text out to file pw.println(strategy.getResultantText()); } catch (ExceptionConverter e) { e.printStackTrace(); ret = false; pw.println("iText Exception: Page " + (i + 1) + ": " + e.getClass().getName() + ": " + e.getMessage()); } } } catch (IOException e) { ret = false; // TODO Auto-generated catch block e.printStackTrace(); } finally { if (pw != null) pw.close(); if (reader != null) reader.close(); } return ret; }