unidoc / unipdf

Golang PDF library for creating and processing PDF files (pure go)
https://unidoc.io
Other
2.56k stars 251 forks source link

Advanced text extraction on columns, tables, equations #38

Open gunnsth opened 5 years ago

gunnsth commented 5 years ago

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.

Ben-harder commented 4 years ago

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

gunnsth commented 4 years ago

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

Ben-harder commented 4 years ago

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.

Alttaf commented 4 years ago

+1 for this

gunnsth commented 4 years ago

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

Ben-harder commented 4 years ago

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

peterwilliams97 commented 4 years ago

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:

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?

Ben-harder commented 4 years ago

Hi Peter, thank you that sounds great!

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

Ben-harder commented 4 years ago

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

peterwilliams97 commented 4 years ago

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

Elikrag commented 4 years ago

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!

gunnsth commented 3 years ago

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