Unable to open PDF Parser. Error: End-of-File, expected line

35 views
Skip to first unread message

eddieB

unread,
Aug 14, 2017, 5:45:37 PM8/14/17
to Selenium Users
I am trying to verify some content of pdf. Pdf opens when the user clicks on print in a new tab.
I am trying the following code 

 //get current urlpdf file url

URL url = new URL(driver.getCurrentUrl());

                 

//create buffer reader object

BufferedInputStream fileToParse = new BufferedInputStream(url.openStream());

PDFParser pdfParser = new PDFParser(fileToParse);

pdfParser.parse();

//save pdf text into strong variable

String pdftxt = new PDFTextStripper().getText(pdfParser.getPDDocument());

                 

//close PDFParser object

pdfParser.getPDDocument().close();

After applying above code, you can store all pdf file content into “pdftxt” string variable. Now you can verify string by giving  in put.  As if you want to verify “Selenium Or Webdiver text. Use below code.

                 

Assert.assertTrue(pdftxt.contains(“Selenium Or Webdiver”))


When run this code I get the error as Unable to open PDF Parser. Error: End-of-File, expected line.

I have followed on this issue a lot but dont see any solution to this issue. ANyone who has encountered this issue and resolved it. Appreciate you input

Reply all
Reply to author
Forward
0 new messages