• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Java selenium parsing PDF file from browser

 
Greenhorn
Posts: 23
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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):


 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

This robot framework doesn't support headless mode.So how to make this code run in headless mode.

Thanks,
Rekha
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic