TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

PDF to Text, a challenging problem

266 点作者 ingve大约 16 小时前

41 条评论

90s_dev大约 12 小时前
Have any of you ever thought to yourself, this is new and interesting, and then vaguely remembered that you spent months or years becoming an expert at it earlier in life but entirely forgot it? And in fact large chunks of the very interesting things you&#x27;ve done just completely flew out of your mind long ago, to the point where you feel absolutely new at life, like you&#x27;ve accomplished relatively nothing, until something like this jars you out of that forgetfulness?<p>I definitely vaguely remember doing some incredibly cool things with PDFs and OCR about 6 or 7 years ago. Some project comes to mind... google tells me it was &quot;tesseract&quot; and that sounds familiar.
评论 #43977155 未加载
评论 #43980118 未加载
评论 #43977580 未加载
评论 #43978171 未加载
评论 #43981115 未加载
评论 #43976796 未加载
评论 #43977605 未加载
评论 #43976023 未加载
评论 #43976086 未加载
评论 #43979324 未加载
herodotus大约 3 小时前
This is mostly what I worked on for many years at Apple with reasonable success. The main secret was to accept that everything was geometry, and use cluster analysis to try to distinguish between word gaps and letter gaps. On many PDF documents, it works really well, but there are so many different kinds of PDF documents that there are always cases were the results are not that great. If I were to do it today, I would stick with geometry, avoid OCR completely, but use machine learning. One big advantage for machine learning is that I could use existing tools to generate PDFs from known text, so that the training phase could be completly automatic. (Here is Bertrand Serlet announcing the feature at WWDC in 2009: <a href="https:&#x2F;&#x2F;youtu.be&#x2F;FTfChHwGFf0?si=wNCfI9wZj1aj9rY7&amp;t=308" rel="nofollow">https:&#x2F;&#x2F;youtu.be&#x2F;FTfChHwGFf0?si=wNCfI9wZj1aj9rY7&amp;t=308</a>)
svat大约 15 小时前
One thing I wish someone would write is something like the browser&#x27;s developer tools (&quot;inspect elements&quot;) for PDF — it would be great to be able to &quot;view source&quot; a PDF&#x27;s content streams (the BT … ET operators that enclose text, each Tj operator for setting down text in the currently chosen font, etc), to see how every “pixel” of the PDF is being specified&#x2F;generated. I know this goes against the current trend &#x2F; state-of-the-art of using vision models to basically “see” the PDF like a human and “read” the text, but it would be really nice to be able to actually understand what a PDF file contains.<p>There are a few tools that allow inspecting a PDF&#x27;s contents (<a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=41379101">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=41379101</a>) but they stop at the level of the PDF&#x27;s objects, so entire content streams are single objects. For example, to use one of the PDFs mentioned in this post, the file <a href="https:&#x2F;&#x2F;bfi.uchicago.edu&#x2F;wp-content&#x2F;uploads&#x2F;2022&#x2F;06&#x2F;BFI_WP_2022-68-1.pdf" rel="nofollow">https:&#x2F;&#x2F;bfi.uchicago.edu&#x2F;wp-content&#x2F;uploads&#x2F;2022&#x2F;06&#x2F;BFI_WP_2...</a> has, corresponding to page number 6 (PDF page 8), a content stream that starts like (some newlines added by me):<p><pre><code> 0 g 0 G 0 g 0 G BT &#x2F;F19 10.9091 Tf 88.936 709.041 Td [(Subsequen)28(t)-374(to)-373(the)-373(p)-28(erio)-28(d)-373(analyzed)-373(in)-374(our)-373(study)83(,)-383(Bridge&#x27;s)-373(paren)27(t)-373(compan)28(y)-373(Ne)-1(wGlob)-27(e)-374(reduced)]TJ -16.936 -21.922 Td [(the)-438(n)28(um)28(b)-28(er)-437(of)-438(priv)56(ate)-438(sc)28(ho)-28(ols)-438(op)-27(erated)-438(b)28(y)-438(Bridge)-437(from)-438(405)-437(to)-438(112,)-464(and)-437(launc)28(hed)-438(a)-437(new)-438(mo)-28(del)]TJ 0 -21.923 Td </code></pre> and it would be really cool to be able to see the above “source” and the rendered PDF side-by-side, hover over one to see the corresponding region of the other, etc, the way we can do for a HTML page.
评论 #43975665 未加载
评论 #43974386 未加载
评论 #43979271 未加载
评论 #43974502 未加载
kbyatnal大约 13 小时前
&quot;PDF to Text&quot; is a bit simplified IMO. There&#x27;s actually a few class of problems within this category:<p>1. reliable OCR from documents (to index for search, feed into a vector DB, etc)<p>2. structured data extraction (pull out targeted values)<p>3. end-to-end document pipelines (e.g. automate mortgage applications)<p>Marginalia needs to solve problem #1 (OCR), which is luckily getting commoditized by the day thanks to models like Gemini Flash. I&#x27;ve now seen multiple companies replace their OCR pipelines with Flash for a fraction of the cost of previous solutions, it&#x27;s really quite remarkable.<p>Problems #2 and #3 are much more tricky. There&#x27;s still a large gap for businesses in going from raw OCR outputs —&gt; document pipelines deployed in prod for mission-critical use cases. LLMs and VLMs aren&#x27;t magic, and anyone who goes in expecting 100% automation is in for a surprise.<p>You still need to build and label datasets, orchestrate pipelines (classify -&gt; split -&gt; extract), detect uncertainty and correct with human-in-the-loop, fine-tune, and a lot more. You can certainly get close to full automation over time, but it&#x27;s going to take time and effort. The future is definitely moving in this direction though.<p>Disclaimer: I started a LLM doc processing company to help companies solve problems in this space (<a href="https:&#x2F;&#x2F;extend.ai" rel="nofollow">https:&#x2F;&#x2F;extend.ai</a>)
评论 #43976790 未加载
评论 #43977158 未加载
评论 #43976203 未加载
dwheeler大约 14 小时前
The better solution is to embed, in the PDF, the editable source document. This is easily done by LibreOffice. Embedding it takes very little space in general (because it compresses well), and then you have MUCH better information on what the text is and its meaning. It works just fine with existing PDF readers.
评论 #43975401 未加载
评论 #43974667 未加载
评论 #43974983 未加载
评论 #43976216 未加载
评论 #43975217 未加载
trevor-e大约 5 小时前
Having built some toy parsers for PDF files in the past it was a huge wtf moment for me when I realized how the format works. With that in mind, it&#x27;s even more puzzling how it&#x27;s used often in text-heavy cases.<p>I always think about the invoicing use-case: digital systems should be able to easy extract data from the file while still being formatted visually for humans. It seems like the tech world would be much better off if we migrated to a better format.
评论 #43980460 未加载
1vuio0pswjnm7大约 12 小时前
Below is a PDF. It is a .txt file. I can save it with a .pdf extension and open it in a PDF viewer. I can make changes in a text editor. For example, by editing this text file, I can change the text displayed on the screen when the PDF is opened, the font, font size, line spacing, the maximum characters per line, number of lines per page, the paper width and height, as well as portrait versus landscape mode.<p><pre><code> %PDF-1.4 1 0 obj &lt;&lt; &#x2F;CreationDate (D:2025) &#x2F;Producer &gt;&gt; endobj 2 0 obj &lt;&lt; &#x2F;Type &#x2F;Catalog &#x2F;Pages 3 0 R &gt;&gt; endobj 4 0 obj &lt;&lt; &#x2F;Type &#x2F;Font &#x2F;Subtype &#x2F;Type1 &#x2F;Name &#x2F;F1 &#x2F;BaseFont &#x2F;Times-Roman &gt;&gt; endobj 5 0 obj &lt;&lt; &#x2F;Font &lt;&lt; &#x2F;F1 4 0 R &gt;&gt; &#x2F;ProcSet [ &#x2F;PDF &#x2F;Text ] &gt;&gt; endobj 6 0 obj &lt;&lt; &#x2F;Type &#x2F;Page &#x2F;Parent 3 0 R &#x2F;Resources 5 0 R &#x2F;Contents 7 0 R &gt;&gt; endobj 7 0 obj &lt;&lt; &#x2F;Length 8 0 R &gt;&gt; stream BT &#x2F;F1 50 Tf 1 0 0 1 50 752 Tm 54 TL (PDF is)&#x27; ((a) a text format)&#x27; ((b) a graphics format)&#x27; ((c) (a) and (b).)&#x27; ()&#x27; ET endstream endobj 8 0 obj 53 endobj 3 0 obj &lt;&lt; &#x2F;Type &#x2F;Pages &#x2F;Count 1 &#x2F;MediaBox [ 0 0 612 792 ] &#x2F;Kids [ 6 0 R ] &gt;&gt; endobj xref 0 9 0000000000 65535 f </code></pre> 0000000009 00000 n 0000000113 00000 n 0000000514 00000 n 0000000162 00000 n 0000000240 00000 n 0000000311 00000 n 0000000391 00000 n 0000000496 00000 n trailer &lt;&lt; &#x2F;Size 9 &#x2F;Root 2 0 R &#x2F;Info 1 0 R &gt;&gt; startxref 599 %%EOF
评论 #43976133 未加载
评论 #43976276 未加载
评论 #43980858 未加载
gerdesj大约 6 小时前
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).<p>So, you start off with the premise that a .pdf stores text and you want that text. Well that&#x27;s nice: grow some eyes!<p>Otherwise, you are going to have to get to grips with some really complicated stuff. For starters, is the text ... text or is it an image? Your eyes don&#x27;t care and will just work (especially when you pop your specs back on) but your parser is probably seg faulting madly. It just gets worse.<p>PDF is for humans to read. Emulate a human to read a PDF.
bartread大约 15 小时前
Yeah, getting text - even structured text - out of PDFs is no picnic. Scraping a table out of an HTML document is often straightforward even on sites that use the &quot;everything&#x27;s a &lt;div&gt;&quot; (anti-)pattern, and especially on sites that use more semantically useful elements, like &lt;table&gt;.<p>Not so PDFs.<p>I&#x27;m far from an expert on the format, so maybe there is some semantic support in there, but I&#x27;ve seen plenty of PDFs where tables are simply an loose assemblage of graphical and text elements that, only when rendered, are easily discernible as a table because they&#x27;re positioned in such a way that they render as a table.<p>I&#x27;ve actually had decent luck extracting tabular data from PDFS by converting the PDFs to HTML using the Poppler PDF utils, then finding the expected table header, and then using the x-coordinate of the HTML elements for each value within the table to work out columns, and extract values for each rows.<p>It&#x27;s kind of groaty but it seems reliable for what I need. Certainly much moreso than going via formatted plaintext, which has issues with inconsistent spacing, and the insertion of newlines into the middle of rows.
评论 #43976596 未加载
评论 #43976252 未加载
评论 #43974220 未加载
ted_dunning大约 13 小时前
One of my favorite documents for highlighting the challenges described here is the PDF for this article:<p><a href="https:&#x2F;&#x2F;academic.oup.com&#x2F;auk&#x2F;article&#x2F;126&#x2F;4&#x2F;717&#x2F;5148354" rel="nofollow">https:&#x2F;&#x2F;academic.oup.com&#x2F;auk&#x2F;article&#x2F;126&#x2F;4&#x2F;717&#x2F;5148354</a><p>The first page is classic with two columns of text, centered headings, a text inclusion that sits between the columns and changes the line lengths and indentations for the columns. Then we get the fun of page headers that change between odd and even pages and section header conventions that vary drastically.<p>Oh... to make things even better, paragraphs doing get extra spacing and don&#x27;t always have an indented first line.<p>Some of everything.
评论 #43975598 未加载
patrick41638265大约 10 小时前
Good old <a href="https:&#x2F;&#x2F;linux.die.net&#x2F;man&#x2F;1&#x2F;pdftotext" rel="nofollow">https:&#x2F;&#x2F;linux.die.net&#x2F;man&#x2F;1&#x2F;pdftotext</a> and a little Python on top of its output will get you a long way if your documents are not too crazy. I use it to parse all my bank statements into an sqlite database for analysis.
gibsonf1大约 13 小时前
We[1] Create &quot;Units of Thought&quot; from PDF&#x27;s and then work with those for further discovery where a &quot;Unit of Thought&quot; is any paragraph, title, note heading - something that stands on its own semantically. We then create a hierarchy of objects from that pdf in the database for search and conceptual search - all at scale.<p>[1] <a href="https:&#x2F;&#x2F;graphmetrix.com&#x2F;trinpod-server" rel="nofollow">https:&#x2F;&#x2F;graphmetrix.com&#x2F;trinpod-server</a> <a href="https:&#x2F;&#x2F;trinapp.com" rel="nofollow">https:&#x2F;&#x2F;trinapp.com</a>
评论 #43977712 未加载
smcleod大约 11 小时前
Definitely recommend docling for this. <a href="https:&#x2F;&#x2F;docling-project.github.io&#x2F;docling&#x2F;" rel="nofollow">https:&#x2F;&#x2F;docling-project.github.io&#x2F;docling&#x2F;</a>
incanus77大约 7 小时前
I did some contract work some years back with a company who had a desktop product (for Mac) that would apply some smarts to strip out extraneous things on pages while printing (such as ads on webpages) as well as try to avoid the case where only a line or two was printed on a page, wasting paper. It initially was getting into things at the PostScript layer, which unsurprisingly was horrifying, but eventually worked on PDFs. This required finding and interpreting various textual parts of the passed documents and was a pretty big technical challenge.<p>While I&#x27;m not convinced it was viable at the business level, it feels like something platform&#x2F;OS companies could focus on to have a measurable environmental and cost overhead impact.
bob1029大约 14 小时前
When accommodating the general case, solving PDF-to-text is approximately equivalent to solving JPEG-to-text.<p>The only PDF parsing scenario I would consider putting my name on is scraping AcroForm field values from standardized documents.
评论 #43974604 未加载
评论 #43974634 未加载
xnx大约 15 小时前
Weird that there&#x27;s no mention of LLMs in this article even though the article is very recent. LLMs haven&#x27;t solved every OCR&#x2F;document data extraction problem, but they&#x27;ve dramatically improved the situation.
评论 #43974337 未加载
评论 #43974325 未加载
评论 #43974562 未加载
评论 #43975686 未加载
评论 #43974229 未加载
wrs大约 15 小时前
Since these are statistical classification problems, it seems like it would be worth trying some old-school machine learning (not an LLM, just an NN) to see how it compares with these manual heuristics.
评论 #43974445 未加载
rekoros大约 8 小时前
I&#x27;ve been using Azure&#x27;s &quot;Document Intelligence&quot; thingy (prebuilt &quot;read&quot; model) to extract text from PDFs with pretty good results [1]. Their terminology is so bad, it&#x27;s easy to dismiss the whole thing for another Microsoft pile, but it actually, like, for real, works.<p>[1] <a href="https:&#x2F;&#x2F;learn.microsoft.com&#x2F;en-us&#x2F;azure&#x2F;ai-services&#x2F;document-intelligence&#x2F;prebuilt&#x2F;read?view=doc-intel-4.0.0&amp;tabs=sample-code" rel="nofollow">https:&#x2F;&#x2F;learn.microsoft.com&#x2F;en-us&#x2F;azure&#x2F;ai-services&#x2F;document...</a>
remram大约 6 小时前
I built a simple OSS tool for qualitative data analysis, which needs to turn uploaded documents into text (stripped HTML). PDFs have been a huge problem from day one.<p>I have investigated many tools, but two-column layouts and footers etc often still mess up the content.<p>It&#x27;s hard to convince my (often non-technical) users that this is a difficult problem.
Sharlin大约 10 小时前
Some of the unsung heroes of the modern age are the programmers who, through what must have involved a lot of weeping and gnashing of teeth, have managed to implement the find, select, and copy operations in PDF readers.
noosphr大约 10 小时前
I&#x27;ve worked on this in my day job: extracting _all_ relevant information from a financial services PDF for a bert based search engine.<p>The only way to solve that is with a segmentation model followed by a regular OCR model and whatever other specialized models you need to extract other types of data. VLM aren&#x27;t ready for prime time and won&#x27;t be for a decade on more.<p>What worked was using doclaynet trained YOLO models to get the areas of the document that were text, images, tables or formulas: <a href="https:&#x2F;&#x2F;github.com&#x2F;DS4SD&#x2F;DocLayNet">https:&#x2F;&#x2F;github.com&#x2F;DS4SD&#x2F;DocLayNet</a> if you don&#x27;t care about anything but text you can feed the results into tesseract directly (but for the love of god read the manual). Congratulations, you&#x27;re done.<p>Here&#x27;s some pre-trained models that work OK out of the box: <a href="https:&#x2F;&#x2F;github.com&#x2F;ppaanngggg&#x2F;yolo-doclaynet">https:&#x2F;&#x2F;github.com&#x2F;ppaanngggg&#x2F;yolo-doclaynet</a> I found that we needed to increase the resolution from ~700px to ~2100px horizontal for financial data segmentation.<p>VLMs on the other hand still choke on long text and hallucinate unpredictably. Worse they can&#x27;t understand nested data. If you give _any_ current model nothing harder than three nested rectangles with text under each they will not extract the text correctly. Given that nested rectangles describes every table no VLM can currently extract data from anything but the most straightforward of tables. But it will happily lie to you that it did - after all a mining company should own a dozen bulldozers right? And if they each cost $35.000 it must be an amazing deal they got, right?
评论 #43978106 未加载
EmilStenstrom大约 14 小时前
I think using Gemma3 in vision mode could be a good use-case for converting PDF to text. It’s downloadable and runnable on a local computer, with decent memory requirements depending on which size you pick. Did anyone try it?
评论 #43976271 未加载
评论 #43975132 未加载
coolcase大约 8 小时前
Tried extracting data from a newspaper. It is really hard. What is a headline and which headline belongs to which paragraphs? Harder than you think! And chucking it as is into OpenAI was no good at all. Manually dealing with coordinates from OCR was better but not perfect.
rad_gruchalski大约 15 小时前
So many of these problems have been solved by mozilla pdf.js together with its viewer implementation: <a href="https:&#x2F;&#x2F;mozilla.github.io&#x2F;pdf.js&#x2F;" rel="nofollow">https:&#x2F;&#x2F;mozilla.github.io&#x2F;pdf.js&#x2F;</a>.
评论 #43974428 未加载
评论 #43974240 未加载
评论 #43975184 未加载
elpalek大约 11 小时前
Recently tested a (non-english) pdf ocr with Gemini 2.5 Pro. First, directly ask it to extract text from pdf. Result: random text blob, not useable.<p>Second, I converted pdf into pages of jpg. Gemini performed exceptional. Near perfect text extraction with intact format in markdown.<p>Maybe there&#x27;s internal difference when processing pdf vs jpg inside the model.
评论 #43977077 未加载
PeterStuer大约 12 小时前
I guess I&#x27;m lucky the PDF&#x27;s I need to process are mostly rather dull unadventurous layouts. So far I&#x27;ve had great success using docling.
nicodjimenez大约 12 小时前
Check out mathpix.com. We handle complex tables, complex math, diagrams, rotated tables, and much more, extremely accurately.<p>Disclaimer: I&#x27;m the founder.
viking2917大约 7 小时前
coincidentally, posted this over on Show HN today. OCR workbench, AI OCR &amp; editing tools for OCRing old &#x2F; hard documents. <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=43976450">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=43976450</a>. Tesseract works fine for modern text documents, but it fails badly on older docs (e.g. colonial american, etc)
fracus大约 6 小时前
Why hasn&#x27;t the PDF standard been replaced or revised to require the text in meta form? Seems like a no brainer.
评论 #43980871 未加载
andrethegiant大约 14 小时前
Cloudflare’s ai.toMarkdown() function available in Workers AI can handle PDFs pretty easily. Judging from speed alone, it seems they’re parsing the actual content rather than shoving into OCR&#x2F;LLM.<p>Shameless plug: I use this under the hood when you prefix any PDF URL with <a href="https:&#x2F;&#x2F;pure.md&#x2F;" rel="nofollow">https:&#x2F;&#x2F;pure.md&#x2F;</a> to convert to raw text.
评论 #43974514 未加载
评论 #43974535 未加载
评论 #43974602 未加载
评论 #43975027 未加载
bickfordb大约 11 小时前
Maybe it&#x27;s time for new document formats and browsers that neatly separate content, presentation and UI layers? PDF and HTML are 20+ years old and it&#x27;s often difficult to extract information from either let alone author a browser.
评论 #43976780 未加载
ljlolel大约 12 小时前
Mistral OCR has best in class doing document understanding<p><a href="https:&#x2F;&#x2F;mistral.ai&#x2F;news&#x2F;mistral-ocr" rel="nofollow">https:&#x2F;&#x2F;mistral.ai&#x2F;news&#x2F;mistral-ocr</a>
devrandoom大约 13 小时前
I currently use ocrmypdf for my private library. Then Recoll to index and search. Is there a better solution I&#x27;m missing?
anonu大约 12 小时前
They should called it NDF - Non-Portable Document Format.
评论 #43980779 未加载
dobraczekolada大约 12 小时前
Reminds me of github.com&#x2F;docwire&#x2F;docwire
TZubiri大约 6 小时前
As someone who has worked on this FT. (S&amp;P, parsing of financial disclosures)<p>The solution is OCR. Don&#x27;t fuck with internal file format. PDF is designed to print&#x2F;display stuff, not to be parseable by machines.
constantinum大约 13 小时前
PDF parsing is hell indeed, with all sorts of edge cases that breaks business workflows, more on that here <a href="https:&#x2F;&#x2F;unstract.com&#x2F;blog&#x2F;pdf-hell-and-practical-rag-applications&#x2F;" rel="nofollow">https:&#x2F;&#x2F;unstract.com&#x2F;blog&#x2F;pdf-hell-and-practical-rag-applica...</a>
keybored大约 12 小时前
For people who want people to read their documents[1] they should have their PDF point to a more digital-friendly format, an alt document.<p><i>Looks like you’ve found my PDF. You might want this version instead:</i><p>PDFs are often subpar. Just see the first example: standard Latex serif section title. I mean, PDFs often aren’t even well-typeset for what they are (dead-tree simulations).<p>[1] No sarcasm or truism. Some may just want to submit a paper to whatever publisher and go through their whole laundry list of what a paper ought to be. Wide dissemanation is not the point.
j45大约 15 小时前
Part of a problem being challenging is recognizing if it&#x27;s new, or just new to us.<p>We get to learn a lot when something is new to us.. at the same time the untouchable parts of PDF to Text are largely being solved with the help of LLMs.<p>I built a tool to extract information from PDFs a long time ago, and the break through was having no ego or attachment to any one way of doing it.<p>Different solutions and approaches offered different depth or quality of solutions and organizing them to work together in addition to anything I built myself provided what was needed - one place where more things work.. than not.
Obscurity4340大约 14 小时前
Is this what GoodPDF does?
reify大约 14 小时前
<a href="https:&#x2F;&#x2F;github.com&#x2F;jalan&#x2F;pdftotext">https:&#x2F;&#x2F;github.com&#x2F;jalan&#x2F;pdftotext</a><p>pdftotext -layout input.pdf output.txt<p>pip install pdftotext