Header recognition is incomplete,table with border in pdf #1177
stevenwu2017
started this conversation in
Ask for help with specific PDFs
Replies: 1 comment 1 reply
-
It seems that there are two issues:
Filtering out those extra graphical elements seems to work: def check(obj):
# Keep only `chars` and objects with a black fill
return obj.get("text") or obj.get("non_stroking_color") == (0, 0, 0)
page.filter(check).to_image().debug_tablefinder() page.filter(check).extract_tables()
|
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I had a problem with incomplete header recognition, table with border in pdf.
but i don't know what causes it. pdf file and debug table find result as follows:
02498_ZH.pdf
![image_01](https://private-user-images.githubusercontent.com/27179507/352762062-9d0df228-4cf5-4d5e-ab80-38a8ca974339.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjYwMzU2NDUsIm5iZiI6MTcyNjAzNTM0NSwicGF0aCI6Ii8yNzE3OTUwNy8zNTI3NjIwNjItOWQwZGYyMjgtNGNmNS00ZDVlLWFiODAtMzhhOGNhOTc0MzM5LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA5MTElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwOTExVDA2MTU0NVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTk0YzI1ZjQyMTFlNzU5NmQxNTc1NWYxNTNmY2VjN2M2OGM1NGNjYTczNzY0ZmNmOWY4ODdkM2Q1YWViOTdmYmUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.Ojf5EcVPkzpcDIx8KnhlyeZ2E95FatkdItrbZkXlsyc)
![image_02](https://private-user-images.githubusercontent.com/27179507/352762066-b330bb9d-ad25-4166-92ff-821863f7e54e.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjYwMzU2NDUsIm5iZiI6MTcyNjAzNTM0NSwicGF0aCI6Ii8yNzE3OTUwNy8zNTI3NjIwNjYtYjMzMGJiOWQtYWQyNS00MTY2LTkyZmYtODIxODYzZjdlNTRlLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA5MTElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwOTExVDA2MTU0NVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWI0ZDZlNGM0YjRmMTNjMDM4M2Q3NTIxNTNjMjYyNDQyNTQxYjIwMGI3ZWEyMDg5ODE4YmY0MDcwMjA1MTJmZDMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.WgwUCYPTnN7XUGiP1ekpp07K2BA4XodPfqHxyM552Dg)
python code:
import pdfplumber
pdf_files = '02498_ZH.pdf'
with pdfplumber.open(pdf_files) as pdf:
# 遍历每个页面
for idx, page in enumerate(pdf.pages):
# if idx==0:
deduped_page = page.dedupe_chars()
tables = page.find_tables()
for table in tables:
content=table.extract()
print(content)
sub_page=page.crop(table.bbox)
im = sub_page.to_image(resolution=200)
im.debug_tablefinder().show()
Beta Was this translation helpful? Give feedback.
All reactions