Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PDFPlumber - A filter to remove superscipt #289

Open
cloudyyoung opened this issue Jun 28, 2023 · 0 comments
Open

PDFPlumber - A filter to remove superscipt #289

cloudyyoung opened this issue Jun 28, 2023 · 0 comments

Comments

@cloudyyoung
Copy link
Member

cloudyyoung commented Jun 28, 2023

Recall how PDFPlumber extracts superscript text as a part of the cell text, like "Assignment 11".

tables = pdf.pages[1].extract_tables()

for table in tables:
    for row in table:
        print(row)
Screenshot 2023-06-28 at 11 57 33 PM Screenshot 2023-06-28 at 11 57 20 PM

Programmatically using a filter on the page can get rid of superscript texts.

def filter(obj):
    if obj["object_type"] == "char" and obj["size"] >= 7.0:
        return True
    elif obj["object_type"] != "char":
        return True

When the object is a character, the normal size character size around 7.200000099000022 but the superscript text is only 6.000000082499923. Excluding specific characters by their size can be used.

Dictionary data structure of a "char":

Screenshot 2023-06-29 at 12 02 51 AM

Now:

# print table
def filter(obj):
    if obj["object_type"] == "char" and obj["size"] >= 7.0:
        return True
    elif obj["object_type"] != "char":
        return True

tables = pdf.pages[1].filter(filter).extract_tables()

for table in tables:
    for row in table:
        print(row)

We can extract table to this better version:

Screenshot 2023-06-29 at 12 03 53 AM

This is not the only approach to realize for the filter, condition on the y0 and y1 might do it too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant