aws-samples / aws-samples/amazon-textract-textractor

issue with ordering in extractions, markdown and gettext methods

Open
#388 14 comments 0 reactions 0 assignees View on GitHub
Dominant language
Jupyter Notebook
Stars
493
Forks
163
PR merge metrics
No merged PRs in 30d

Description

the attached input document contains text then a table followed by some text, we want the text file to be the same as the input pdf file.

![input_page](https://github.com/user-attachments/assets/fe09d250-6547-4eff-bc8f-854f9316b28b)

I tried extraction using different methods:

for 1.) and 2.) this is the code I am using:
`
textract_json = extractor.start_document_analysis(
file_source="s3://s3sagemakerbucket/textract_analysis/12382593_bnp_credit_facility_20m.pdf",
features=[TextractFeatures.LAYOUT, TextractFeatures.TABLES],
save_image=False,
)`
`response_textract_async = extractor.get_result(job_id=textract_json.job_id, api=Textract_API.ANALYZE)`
`markdown_text = response_textract_async.to_markdown()
`
1.) .to_markdown() method
![using_markdown_method](https://github.com/user-attachments/assets/7ff7187b-d9ec-42a1-a04a-20312c842a86)
the issue here is the two table are at the bottom.

2.) .get_text() method
![using_gettext_method](https://github.com/user-attachments/assets/4d2e95b9-1a68-4129-ac55-c8601039088b)
in this case as well we can see the two tables are at the bottom and like we know without config parameter we wont get markdown output.

now the third is interesting
the code used for this is:
`from textractcaller.t_call import call_textract, Textract_Features`
`from textractprettyprinter.t_pretty_print import get_text_from_layout_json`

`textract_json = call_textract(input_document="s3://s3sagemakerbucket/textract_analysis/12382593_bnp_credit_facility_20m.pdf",
features=[Textract_Features.LAYOUT,Textract_Features.TABLES],)
`
3.) get_text_from_layout_json(textract_json=textract_json)
also tried with get_text_from_layout_json(textract_json=textract_json, generate_markdown = True) in both of these cases getting the same output.
![using_gettextfromlayout_1](https://github.com/user-attachments/assets/42f36214-5ebf-4d04-b980-f689f5aba05c)
![using_gettextfromlayout_2](https://github.com/user-attachments/assets/c2a836a2-57a5-4bc5-8ad0-f22741fbb8f3)

the issue in using this method is like you can see, the data is getting repeated twice, also there is no markdown format present.

@Belval or anyone can you please suggest if there is anything we can do to prevent this and get the text in correct like we have in the pdf file.

Thanks.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.