A
A
Anton @ Lyalin2017-02-23 10:29:36
Java
Anton @ Lyalin, 2017-02-23 10:29:36

What is wrong with pdfbox???

String text = "";

/*В этом месте всегда ругается на данную строку. Пишет (PDFParser (org.apache.pdfbox.io.RandomAccessRead)
in PDFParser cannot be applied to (java.io.FileInputStream))*/

        pdfParser = new PDFParser(new FileInputStream(filePath));

        pdfParser.parse();
        cosDocument = pdfParser.getDocument();
        pdfTextStripper = new PDFTextStripper();
        pdDocument = new PDDocument(cosDocument);
        pdDocument.getNumberOfPages();
        pdfTextStripper.setStartPage(1);
        pdfTextStripper.setEndPage(10);

        // reading text from page 1 to 10
        // if you want to get text from full pdf file use this code
        // pdfStripper.setEndPage(pdDoc.getNumberOfPages());

        text = pdfTextStripper.getText(pdDocument);

        return text;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
aol-nnov, 2017-02-23
@toxa_1995

Well, it says what's wrong!
see the documentation: https://pdfbox.apache.org/docs/2.0.0/javadocs/org/...
FileInputStream does not implement org.apache.pdfbox.io.RandomAccessRead
RandomAccessFile needs to be there, for example.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question