Example usage for com.itextpdf.text ExceptionConverter printStackTrace

List of usage examples for com.itextpdf.text ExceptionConverter printStackTrace

Introduction

In this page you can find the example usage for com.itextpdf.text ExceptionConverter printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

we have to override this as well

Usage

From source file:uk.bl.dpt.qa.flint.wrappers.iTextWrapper.java

License:Apache License

/**
 * Extracts text from a PDF./*from   www .  ja  v a 2s .c o 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;
}