Live data from Hacker News

Show HN: Parsing horse racing charts with Apache PDFBox

github.com

21–30 of 32 posts

Re: Show HN: Parsing horse racing charts with Apache PDFBox

#21
post #9

Very interesting! I had never heard of Apache PDFBox before, I must give it a try. I have a similar program that parses horse racing PDFs from sites such as www.racehorserunner.com - which are of a much simpler format, but cause endless problems for me when the PDFs have layout problems. For example, issues like one column being too long and overlapping with another, e.g the last race on http://www.racehorserunner.co…

Yes I encountered similar issues but many of them were able to be solved.

With PDFBox I was able to deal with the content at a very low level (on a per-character basis), so that when for instance building a String, I would insert a pipe character when the distance between adjacent characters was greater than the width of the space character and then detect that when translating to a certain field.

See the convertToText() method for an example: https://github.com/robinhowlett/chart-parser/blob/master/src...

and https://github.com/robinhowlett/chart-parser/blob/f8d651e9a1... for when I used this technique

Re: Show HN: Parsing horse racing charts with Apache PDFBox

#22
post #9

Very interesting! I had never heard of Apache PDFBox before, I must give it a try. I have a similar program that parses horse racing PDFs from sites such as www.racehorserunner.com - which are of a much simpler format, but cause endless problems for me when the PDFs have layout problems. For example, issues like one column being too long and overlapping with another, e.g the last race on http://www.racehorserunner.co…

Yes I encountered similar issues but many of them were able to be solved. With PDFBox I was able to deal with the content at a very low level (on a per-character basis), so that when for instance building a String, I would insert a pipe character when the distance between adjacent characters was greater than the width of the space character and then detect that when translating to a certain field. See the convertToTe…

Very cool, good to see the level of control this package allows.

Re: Show HN: Parsing horse racing charts with Apache PDFBox

#23
post #9

Very interesting! I had never heard of Apache PDFBox before, I must give it a try. I have a similar program that parses horse racing PDFs from sites such as www.racehorserunner.com - which are of a much simpler format, but cause endless problems for me when the PDFs have layout problems. For example, issues like one column being too long and overlapping with another, e.g the last race on http://www.racehorserunner.co…

PDFBox committer here, if you want even lower-level access to the page content stream, without anything 'clever' at all, check out the PDFGraphicsStreamEngine class, which is a superclass of the text extraction and rendering classes. Gives you access to the raw glyphs. You can override PageRenderer too, for visual debugging, e.g. render glyph bounding boxes. We have an interactive Swing PDFDebugger which does just that.

https://github.com/apache/pdfbox/blob/6f18d7c4bef4d23a22d/ex...

Re: Show HN: Parsing horse racing charts with Apache PDFBox

#24
post #5

Earlier quoted context omitted.

that's still presenting the pages in portrait orientation. I want the pages to be landscape and for the text to flow in at least 2 columns.

PDF is used primarily for pre-paginated media and does not reflow text; if the PDF author wanted the pages in landscape orientation, or using some other paper dimensions, he would have specified that. Same goes for margins and the like.

ok, that's what the author wanted, but they're wrong. We are reading our text on computers in 2017 - we should be able to choose the format that reads best for us.

Re: Show HN: Parsing horse racing charts with Apache PDFBox

#25
post #10

I still don't understand how PDF could become one of the standards for publishing documents. Well structured content gets converted into PDF which loses most of that structure. And then a lot of work is done to guess that structure from PDF and convert it back to a better file format. It just shows that successful solutions don't have to be technically good.

PDF has a feature called Tagged PDF, which allows the document to be annotated with a semantic structure. Almost nobody bothers to generate such PDFs, but the support is there!

Re: Show HN: Parsing horse racing charts with Apache PDFBox

#26
post #10

I still don't understand how PDF could become one of the standards for publishing documents. Well structured content gets converted into PDF which loses most of that structure. And then a lot of work is done to guess that structure from PDF and convert it back to a better file format. It just shows that successful solutions don't have to be technically good.

The keyword is "publishing" --- as in, producing human-readable physical copies, not electronic ones. It just so happens that the format was relatively suitable for the latter too (because it actually looks like a printed document rendered on the screen --- unlike HTML or other formats around at the time), which is why that use-case became popular. PDF is basically a descendant of PostScript, which was designed to co…

Minimal PDF explained: https://brendanzagaeski.appspot.com/0004.html

Re: Show HN: Parsing horse racing charts with Apache PDFBox

#28

As a python programmer, I found R's pdftools to be indispensable for messy text based PDFs. I couldn't find a python lib that worked as consistently across variously different formats.

I came across https://github.com/pdfminer/pdfminer.six recently and was impressed with what it could get done. The documentation can be challenging to parse, so I relied on a code sample from a StackOverflow answer. Have you had a chance to try it out? Curious about how/if it works well across platforms.

Re: Show HN: Parsing horse racing charts with Apache PDFBox

#29

Earlier quoted context omitted.

Doesn't mean the author isn't wrong for my reading situation... Or isn't doing it just cause everyone else is.

I think what the parent is trying to say is that PDF is not like HTML or text or other formats where the viewer is primarily responsible for a lot of the formatting --- in fact, a PDF page contains not much more than primitive instructions of the form "move to X, Y"; "set font to F"; "draw text 'Some text here'" (some pathological cases issue individual moves and draws for each character ) --- so expecting all PDF vi…

I totally get that; however since these days a standard sheet of papers is no longer the main reading mechanism... I'm not sure it's the best layout for reading. My brother is a PhD and reads papers all day. He hates the two column format and paid for a reflowing reader. PDF is terrible on screens with different ratios than paper... Eg good computers and mobile. As I get older I use my plethora of giant screens to crank the fonts way up and sit back relaxed. PDF is terrible in that situation.

Just a thought... Maybe highly formatted PDFs for paper print shouldn't be the standard anymore. Eg my original point.

Re: Show HN: Parsing horse racing charts with Apache PDFBox

#30
post #9

Very interesting! I had never heard of Apache PDFBox before, I must give it a try. I have a similar program that parses horse racing PDFs from sites such as www.racehorserunner.com - which are of a much simpler format, but cause endless problems for me when the PDFs have layout problems. For example, issues like one column being too long and overlapping with another, e.g the last race on http://www.racehorserunner.co…

PDFBox committer here, if you want even lower-level access to the page content stream, without anything 'clever' at all, check out the PDFGraphicsStreamEngine class, which is a superclass of the text extraction and rendering classes. Gives you access to the raw glyphs. You can override PageRenderer too, for visual debugging, e.g. render glyph bounding boxes. We have an interactive Swing PDFDebugger which does just th…

Thanks for the guidance, I'll take a look.
Post reply on HN