• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Java selenium parsing PDF file from browser

 
Greenhorn
Posts: 23
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,

I'm trying to parse a PDF file that is opened in Chrome. Here is the relevant code:

Main Class:




ReadPDF Class:

 


Console error message:

Exception in thread "main" java.io.IOException: Error: End-of-File, expected line
at org.apache.pdfbox.pdfparser.BaseParser.readLine(BaseParser.java:1519)
at org.apache.pdfbox.pdfparser.PDFParser.parseHeader(PDFParser.java:360)
at org.apache.pdfbox.pdfparser.PDFParser.parse(PDFParser.java:186)
at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:1230)
at org.apache.pdfbox.pdmodel.PDDocument.load(PDDocument.java:1197)
at switzerlandDB.ReadPDF.readPDF(ReadPDF.java:36)
at switzerlandDB.SwitzerlandDB.main(SwitzerlandDB.java:1182)

The error "at switzerlandDB.ReadPDF.readPDF(ReadPDF.java:36)" referes to this line:



The error at "switzerlandDB.SwitzerlandDB.main(SwitzerlandDB.java:1182)" referes to this line:




Anyone knows what am I doing wrong?
Thank you!
 
Master Rancher
Posts: 4669
49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure that that is actually a PDF file in the stream?
Have you tried to save the data in the stream to a file and see what is actually in it, rather than try and treat it as a PDF straight away.
 
Milos Radovic
Greenhorn
Posts: 23
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It turns out that it is an embedded PDF.

The URL looks similar to this: http://something.com/printed.php?printable=yes&reanudar=&detalle=&idioma=1¬ax=no&smart=3&pageBreaks=[]
The source code looks like this:





You have any idea how to solve this?
 
Dave Tolls
Master Rancher
Posts: 4669
49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No idea.
So I take it that URL does not return a PDF?
 
Milos Radovic
Greenhorn
Posts: 23
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I just paste the URL into the browser it returns me to the login page of the application.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Were you able to find a solution for your issue? if so it would be really helpful if you could post it here
 
Milos Radovic
Greenhorn
Posts: 23
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys, in the end, I solved the problem by downloading the PDF on my computer using Javas Robot Class and then parse the PDF.

The ReadPDFde class:






Mian Class (GermanyDB):


 
reply
    Bookmark Topic Watch Topic
  • New Topic