Extract table data from PDF [closed]

会有一股神秘感。 提交于 2019-12-30 04:44:07

问题


Is there any consistent way to extract tables from PDF files? Any tools?

What I have done so far:

  • I have tried out pdftotext tool. It has an option to convert to HTML layout.

What is the problem with this:

  • The table information is not preserved in HTML output
  • I expected <table> tags, but everything was under <p> tags.

Will there be any markers in a PDF document to indicate table structures? Like <table>, <tr> and <td> in HTML?

If "yes", any pointers to this would be helpful. If "no", a definite info about this fact is also helpful.


回答1:


If the PDF document misses information that marks content as table, row, cell, etc. (known as tags), then there is no consistent way to extract tables from the PDF document. Mostly, PDF documents do not contain these tags. These tags typically serve to make a PDF accessible so that it can for example be read aloud. These tags are not required for a PDF to be valid.




回答2:


What you could do however, is use the pdftotext -layout input.pdf output.txt. It prints the pdf in a text file and contains the original layout. There are no tags, but with a bit of nifty scripting (perl / php / whatever), you can recover the data from the tables.

If you're working on a single page, you're probably better off doing it manually, but if you (like me) have to work on 100's or 1000's of pages, it's about the best you can get. I've been looking around for a long time and can't find any better pdf-2-text tool than pdftotext.

There is a bit of inconsistency in the output, not all similar pdf tables produce a similar looking txt output, but that makes your scripting a little more interesting.



来源:https://stackoverflow.com/questions/23495372/extract-table-data-from-pdf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!