unipdf icon indicating copy to clipboard operation
unipdf copied to clipboard

Advanced text extraction on columns, tables, equations

Open gunnsth opened this issue 5 years ago • 12 comments

To properly extract certain text in PDF, it may be necessary to detect/group lines, identify tables, equations. This may either be done post-extraction of objects or before, depending on what is easier to implement and gives good results.

Also need to assemble a solid corpus for testing, as well as an API prototyping. Tabular extraction may need a different approach than equations and possibly a different API.

At this point we are collecting input so that we can define this issue better.

gunnsth avatar Jan 01 '19 14:01 gunnsth

Any update on this? I've found that unfortunately table extraction seems to be about 50% correct at the moment

Ben-harder avatar Aug 26 '20 17:08 Ben-harder

@Ben-harder Can you post some cases where it falls short? And also the code you are using.

gunnsth avatar Aug 26 '20 18:08 gunnsth

Sure. We're using v3.9.0 and we're getting the pageText object for each page and then I've iterated through pageText.Tables() and drawn out the cell bbox's in blue and their bbox's unioned in red to represent the whole table. You can ignore the green outlines.

Here's an example of what we want with one of the tables it picked up perfectly: table_good_1

And here are some examples of where it either picks up lists and thinks they're tables, or it misses some cells in an actual table: 1. table_bad_1 2. table_bad_2 3. table_bad_3

It also picked up a few numbered lists as well.

Ben-harder avatar Aug 26 '20 18:08 Ben-harder

+1 for this

Alttaf avatar Aug 26 '20 18:08 Alttaf

@Ben-harder Can you share some PDFs that we can use for testing and include in our QA and automated test suites?

gunnsth avatar Aug 26 '20 18:08 gunnsth

Sure I can give you the one from the images Speer_Permit.pdf Speer_Permit_overlay.pdf

Ben-harder avatar Aug 26 '20 19:08 Ben-harder

Ben, I will investigate this. I have am working on a few versions of table extraction code that I have not submitted yet. They address most/all of the issues you raise but they make other trade-offs so have been holding them back.

Some of the things I am working on are:

  • Grid line detection fixes a lot of cases
  • Sparse table detection can be tricky
  • Detecting tables without gridlines requires making some judgments

I will see if I can make a small commit that addresses your specific issues next week. Have you been using any other PDF table extractors? If so, can you tell me which one does the best job on you files?

peterwilliams97 avatar Aug 28 '20 00:08 peterwilliams97

Hi Peter, thank you that sounds great!

And no, I haven't used any other PDF table extractors.

Ben-harder avatar Aug 28 '20 01:08 Ben-harder

So we actually have used AWS Textract, my bad. The results from it on the same document are attached. It's a JSON file, just had to convert it so GitHub would let me upload it.

Speer_Permit 18WE0486.CP1_Blowdown vent.txt

Ben-harder avatar Aug 31 '20 17:08 Ben-harder

Thanks. That will give me a benchmark to compare against.

peterwilliams97 avatar Sep 01 '20 11:09 peterwilliams97

Following up on the examples @Ben-harder posted. Examples 1 and 2 are fixed from v3.11.1, but the issue with 3 remains. Here's two more examples from the same PDF:

Screenshot from 2020-10-02 16-42-00

Screenshot from 2020-10-02 16-42-22

Along with Ben's 3rd example still not getting fully picked up:

ex3

Seems like table identification improved, but cell identification within a table didn't. Curious if there's any update on this? Thanks!

Elikrag avatar Oct 02 '20 23:10 Elikrag

Table extractions have been improved in v3.13.0 and you should see much better results with your files.

gunnsth avatar Oct 19 '20 16:10 gunnsth