0

I have been trying to read a pdf which is opened in browser. through the following selenium code.

    URL pdfURL = new URL(driver.getCurrentUrl());            
    InputStream is = pdfURL.openStream();
    BufferedInputStream fileToParse= new BufferedInputStream(is);
    PDFParser pdfParser=new PDFParser(fileToParse);
    pdfParser.parse(); // getting error here !!! 

Getting Error:

java.io.IOException: Error: End-of-File, expected lineenter code here

How to get rid of this error?

Roman Pokrovskij
  • 9,449
  • 21
  • 87
  • 142
  • Get the latest PDFBox version, make sure your PDF file isn't empty, and really is a PDF, and use current API which is `PDDocument.load(pdfURL.openStream());`. – Tilman Hausherr Jan 31 '19 at 13:11
  • I used latest version 2.0.13 and used the below code. Still the same error. Can anyone help. URL pdfURL = new URL(driver.getCurrentUrl()); InputStream is = pdfURL.openStream(); BufferedInputStream fileToParse= new BufferedInputStream(is); PDDocument document= PDDocument.load(fileToParse);//error at this output=new PDFTextStripper().getText(document); – user2995137 Feb 01 '19 at 11:35
  • Please share the file. If you can't share it, save it to a local file to make sure it is not empty. If it isn't empty, make sure it is a Pdf. These start with "%PDF" and a version number. (open it with NOTEPAD++ to look) – Tilman Hausherr Feb 01 '19 at 11:44

0 Answers0