Live data from Hacker News

So you want to parse a PDF?

eliot-jones.com

81–90 of 236 posts

Re: So you want to parse a PDF?

#81
post #15

Disclaimer - Founder of Tensorlake, we built a Document Parsing API for developers. This is exactly the reason why Computer Vision approaches for parsing PDFs works so well in the real world. Relying on metadata in files just doesn't scale across different source of PDFs. We convert PDFs to images, run a layout understanding model on them first, and then apply specialized models like text recognition and table recogn…

It might sound absurd, but on paper this should be the best way to approach the problem.

My understanding is that PDFs are intended to produce an output that is consumed by humans and not by computers, the format seems to be focused on how to display some data so that a human can (hopefully) easily read them. Here it seems that we are using a technique that mimics the human approach, which would seem to make sense.

It is sad though that in 30+ years we didn't manage to add a consistent way to include a way to make a PDF readable by a machine. I wonder what incentives were missing that didn't make this possible. Does anyone maybe have some insight here?

Re: So you want to parse a PDF?

#82

Earlier quoted context omitted.

PDFs don't always lay out characters in sequence, sometimes they have absolutely positioned individual characters instead. PDFs don't always use UTF-8, sometimes they assign random-seeming numbers to individual glyphs (this is common if unused glyphs are stripped from an embedded font, for example) etc etc

But all those problems exist when rendering into a surface or rastering. I just don't understand how one thinks, this is a hard problem, let me make it harder by solving the problem into another kind of problem that is just as hard as solving it in the first place (PDF to structured data vs PDF to raster). And then solve the new problem, which is also hard. It is absurd.

Sometimes scanned documents are structured really weird, especially for tables. Visually, we can recognize the intention when it's rendered, and so can the AI, but you practically have to render it to recover the spatial context.

Re: So you want to parse a PDF?

#83
post #3

> So you want to parse a PDF? Absolutely not. For the reasons in the article.

Would be nice if my banks provided records in a more digestible format, but until then, I have no choice.

I find it pretty sad that for some banks the CSV export is behind a paywall.

Re: So you want to parse a PDF?

#84
post #63

Earlier quoted context omitted.

So you parse PDFs, but also OCR images, to somehow get better results? Do you know you could just use the parsing engine that renders the PDF to get the output? I mean, why raster it, OCR it, and then use AI? Sounds creating a problem to use AI to solve it.

We parse PDFs to convert them to text in a linearized fashion. The use case for this would be to use the content for downstream use cases - search engine, structured extraction, etc.

None of that changes the fact that to get a raster, you have to solve the PDF parsing/rendering problem anyways, so might as well get structured data out instead of pixels so that it now another problem (OCR).

Re: So you want to parse a PDF?

#86
post #59

Earlier quoted context omitted.

I think it's reasonable because their models are probably trained on images, and not whatever "structured data" you may get out of a PDF.

Yes this! We training it on a ton of diverse document images to learn reading order and layouts of documents :)

But you have to render the PDF to get an image, right? How do you go from PDF to raster?

Re: So you want to parse a PDF?

#87

Earlier quoted context omitted.

Seems like a fairly reasonable decision given all the high quality implementations out there.

How is it reasonable to render the PDF, rasterize it, OCR it, use AI, instead of just using the "quality implementation" to actually get structured data out? Sounds like "I don't know programming, so I will just use AI".

> How is it reasonable to render the PDF, rasterize it, OCR it, use AI, instead of just using the "quality implementation" to actually get structured data out?

Because PDFs might not have the data in a structured form; how would you get the structured data out of an image in the PDF?

Re: So you want to parse a PDF?

#88

Earlier quoted context omitted.

PDFs don't always lay out characters in sequence, sometimes they have absolutely positioned individual characters instead. PDFs don't always use UTF-8, sometimes they assign random-seeming numbers to individual glyphs (this is common if unused glyphs are stripped from an embedded font, for example) etc etc

But all those problems exist when rendering into a surface or rastering. I just don't understand how one thinks, this is a hard problem, let me make it harder by solving the problem into another kind of problem that is just as hard as solving it in the first place (PDF to structured data vs PDF to raster). And then solve the new problem, which is also hard. It is absurd.

I don’t think people are suggesting : Build a renderer > build an ocr pipeline > run it on pdfs

I think people are suggesting : Use a readymade renderer > use readymade OCR pipelines/apis > run it on pdfs

A colleague uses a document scanner to create a pdf of a document and sends it to you

You must return the data represented in it retaining as much structure as possible

How would you proceed? Return just the metadata of when the scan was made and how?

Genuinely wondering

Re: So you want to parse a PDF?

#89

Earlier quoted context omitted.

Seems like a fairly reasonable decision given all the high quality implementations out there.

How is it reasonable to render the PDF, rasterize it, OCR it, use AI, instead of just using the "quality implementation" to actually get structured data out? Sounds like "I don't know programming, so I will just use AI".

> instead of just using the "quality implementation" to actually get structured data out?

I suggest spending a few minutes using a PDF editor program with some real-world PDFs, or even just copying and pasting text from a range of different PDFs. These files are made up of cute-tricks and hacks that whatever produced them used to make something that visually works. The high-quality implementations just put the pixels where they're told to. The underlying "structured data" is a lie.

EDIT: I see from further down the thread that your experience of PDFs comes from programmatically generated invoice templates, which may explain why you think this way.

Re: So you want to parse a PDF?

#90

Last weekend I was trying to convert some PDF of Upanishads which contains some Sanskrit and English word. By god its so annoying, I don't think I would be able to without the help of Claude Code with it just reiterating different libraries and methods over and over again. Can we just write things in markdown from now on? I really, really, really, don't care that the images you put is nicely aligned to the right side…

Whole point of PDF is that it's digital paper. It's up to the author how he wants to design it, just like a written note or something printed out and handed to you in person.
Post reply on HN