Live data from Hacker News

PDF to Text, a challenging problem

marginalia.nu

171–180 of 206 posts

Re: PDF to Text, a challenging problem

#171
This was a great read. You've done an excellent job breaking down what makes PDFs so uniquely annoying to work with. People often underestimate how much of the “document-ness” (like headings, paragraphs, tables) is just visual, with no underlying semantic structure.

We ran into many of the same challenges while working on Docsumo, where we process business documents like invoices, bank statements, and scanned PDFs. In real-world use cases, things get even messier: inconsistent templates, rotated scans, overlapping text, or documents generated by ancient software with no tagging at all.

One thing we’ve found helpful (in addition to heuristics like font size/weight and spacing) is combining layout parsing with ML models trained to infer semantic roles (like "header", "table cell", "footer", etc.). It’s far from perfect, but it helps bridge the gap between how the document looks and what it means.

Really appreciate posts like this. PDF wrangling is a dark art more people should talk about.

Re: PDF to Text, a challenging problem

#172
post #156
post #137

Earlier quoted context omitted.

When we get an alternative that can: (1) be stored in a single file (2) Allow tables, images and anything else that can be shown on a piece paper (3) Won't have animation, fold-out text, or anything that cannot be be shown on a piece of paper (4) won't require Javascript or access to external sites that means never.. We've got lucky we at least got PDF before "web designers" made (3) impossible, and marketers made (4…

> (3) Won't have animation, fold-out text, or anything that cannot be be shown on a piece of paper > (4) won't require Javascript or access to external sites So about that... https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsa...

Also: https://pdfa.org/3d-pdf-showcase/

Re: PDF to Text, a challenging problem

#173

PDF is a display format. It is optimised for eyeballs and printers. There has been some feature creep. It is a rubbish machine data transfer mechanism but really good for humans and say storing a page of A4 (letter for the US). So, you start off with the premise that a .pdf stores text and you want that text. Well that's nice: grow some eyes! Otherwise, you are going to have to get to grips with some really complicat…

That's it. I could not have said it better.

Re: PDF to Text, a challenging problem

#174
post #163

Earlier quoted context omitted.

That looks like a pretty good starting point, thanks. I've been dabbling in vision models but need a much higher degree of accuracy than they seem able to provide, opting instead for more traditional techniques and handling errors manually.

For non-table documents a fine tuned yolov8 + tesseract with _good_ image pre-processing has basically a zero percent error rate on monolingual texts. I say basically because the training data has worse labels than what the multi-model system gives out in the cases that I double checked manually. But no one reads the manual on tesseract and everyone ends up feeding it garbage, with predictable results. Tables are an…

Thanks, that's interesting research, I'll look into it.

Re: PDF to Text, a challenging problem

#175
post #161

Earlier quoted context omitted.

(-1) be vector format that never gets pixelated (0) that reproduce everywhere on any OS perfectly (0.5) that supports (everything) any typographical engineers ever wanted past and future Bitmap formats are out from clause -1, Office file formats disqualify from clause 0, Markdown doesn't satisfy clause 0.5. Otherwise a Word .doc format covers most of clauses 1-4.

> (0) that reproduce everywhere on any OS perfectly Can somebody explain why this isn't the case for HTML? I'm frequently in a situation where a website that mimics printed pages fails to render the same between Firefox and Chrome. I wish to understand the primary culprit here. I thought all of the CSS units are completely defined?

I think this is the result of 1) it being a moving target and 2) HTML and CSS being a de facto standard rather than de jure, where the (differing) implementations define at least part of the spec.

You also can't really embed fonts in a HTML file, you rely on linking instead -- and those can rot. Apparently there has been some work towards it (base64 encoded), but support may vary. And you need to embed the whole font, I don't think you can do character subsets easily.

Re: PDF to Text, a challenging problem

#176
post #156
post #137

Earlier quoted context omitted.

When we get an alternative that can: (1) be stored in a single file (2) Allow tables, images and anything else that can be shown on a piece paper (3) Won't have animation, fold-out text, or anything that cannot be be shown on a piece of paper (4) won't require Javascript or access to external sites that means never.. We've got lucky we at least got PDF before "web designers" made (3) impossible, and marketers made (4…

> (3) Won't have animation, fold-out text, or anything that cannot be be shown on a piece of paper > (4) won't require Javascript or access to external sites So about that... https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsa...

Did you miss the meaning of the word "require"?

Re: PDF to Text, a challenging problem

#177
"It doesn’t have text in the way you might think of it, but more of a mapping of glyphs to coordinates on “paper”."

I've often had trouble extracting text from PDFs, it's time consuming and messy, so a quick question. The PDF format is now pretty ancient

Re: PDF to Text, a challenging problem

#178
post #118

Earlier quoted context omitted.

I am hoping at some point to be able to extract tabular data from PDFs for my data wrangling software. If anyone knows of a library that can extract tables from PDFs, can be inegrated into a C++ app and is free or less than a few hundred $, please let me know!

pdfplumber is great for table extraction but it is python

Thanks, but I prefer to keep everything C++ for simplicity and speed.

Re: PDF to Text, a challenging problem

#179
"It doesn’t have text in the way you might think of it, but more of a mapping of glyphs to coordinates on “paper”."

I've often had trouble extracting text from PDFs, it's time consuming and messy, so a quick question.

The PDF format works pretty well for what it does but it's now pretty ancient, so does anyone know if there's any newer format on the horizon that could be a next-generation replacement that would make it much easier to extract its data and export it to another format (say, docx, odt, etc.)?

Re: PDF to Text, a challenging problem

#180
post #137

Earlier quoted context omitted.

We will never get back the collective man-decades of time that has been burned by this format. When will the madness stop?

When we get an alternative that can: (1) be stored in a single file (2) Allow tables, images and anything else that can be shown on a piece paper (3) Won't have animation, fold-out text, or anything that cannot be be shown on a piece of paper (4) won't require Javascript or access to external sites that means never.. We've got lucky we at least got PDF before "web designers" made (3) impossible, and marketers made (4…

Why can't this be done with epub? Single file, all files are packed within the zip, no javascript needed but can be included. Allows for markup and forms, just like pdf.
Post reply on HN