跳到正文
DEV Community· Karthik·· 7 小時前AI 評分47

如何從格式混亂的 PDF 擷取表格,避免逐一手動輸入數字

Pulling tables out of a messy PDF without typing every number by hand

AI 導讀

作者比較 Excel 內置工具、ChatGPT 和專用 OCR 應用程式從 PDF 擷取表格的效果,指出各自適合不同檔案狀況。Excel 適合文字已存在的 PDF,ChatGPT 有助理解版面結構但可能抄錯數字,OCR 則較能處理淡字掃描檔。擷取後應抽查原文中的數字並核對總額。

正文

I had an invoice that came to me as a PDF, and the table inside it had no borders at all. Just numbers floating in columns, with the lines missing. I needed those numbers in Excel, and I did not want to type them out one by one, because that is how a 7 becomes a 1 and a total stops adding up.

So I tried the ways people usually suggest. The first was the hidden tool inside Excel itself. I had never used it before, and I almost did not believe it was there. You point it at the PDF, it looks for the table, and it pulls it into a sheet. On a clean file it worked better than I expected. The columns landed where they belonged, and the numbers came across as numbers, not as text I had to fix afterwards. Where it struggled was the messy part: a row that wrapped onto two lines, and a column where the header was missing. It guessed, and the guess was wrong in one place. I caught it because I checked the total, and the total did not match the invoice. That check saved me. If I had trusted the import without checking, I would have sent someone a wrong figure.

The second way I tried was ChatGPT. I uploaded the same PDF and asked it to give me the table back. It was good at understanding what the table was supposed to be. It knew which column was the date and which one was the amount, even when the layout was awkward. But it was not as careful with the numbers as I needed. On one row it swapped two digits, and on another it left a row out completely because the print was faint. The shape of the answer looked perfect. The contents were not. That is the dangerous kind of mistake, the one that looks right until someone checks it against the original.

The third way was a dedicated OCR app, the kind that is built only for reading documents. It was slower than the other two, and the screen was plain, but it handled the faint print better. It let me tell it where the table was on the page before it started, which felt like extra work at the time. It turned out to be the reason it worked. Because I showed it the area, it did not try to read the whole page at once, and the rows came out in the right order. It still missed one line where the ink had faded badly, and I typed that one in by hand. One line is fine. A whole table is not.

What I took away from that afternoon is that there is no single best way to pull a table out of a PDF. It depends on the file. If the PDF was made from a spreadsheet, so the text is already there and not a picture of text, Excel's own tool is fast and usually right. If the table is borderless and the layout is odd, a chat tool can work out the structure, but you have to check every number it gives you. If it is a scan, or the print is faint, an OCR app that lets you point at the table is the one that gets the most rows right.

I also changed the way I check the result. I do not read the whole table line by line any more. I check the first five rows against the original, then I check the total at the bottom, then I check a few rows in the middle. If those match, I trust the rest a lot more. It takes two minutes, and it has caught a wrong total twice now.

I put the full notes from those tests on AI Tools Reviews, with which approach worked for which kind of file, and where each one went wrong. I wrote it the way I would have wanted to read it before I started: no list of home pages, just what happened when I tried each one on a real invoice with a borderless table.

If you have a messy PDF of your own, start by looking at the file, not at the tools. Is the text already there, or is it a scan? Does the table have borders, or is it just columns of numbers? Is the print clear, or faded? Those three answers narrow it down a lot, and they will save you an afternoon of trying tools at random. The longer version, with the names and the results, is on AI Tool Reviews — I keep updating it when I try a new tool and find it does something different. I also put a shorter version of the same notes on AI Tool Review for anyone who just wants the quick answer.

來源:DEV Community · dev.to