Amazon Textract Pipeline Component to add page dimensions to page block types
Project description
Textract-Pipeline-PageDimensions
Provides functions to add page dimensions with doc_width and doc_height to the Textract JSON schema for the PAGE blocks under the custom attribute in the form of:
e. g.
{'PageDimension': {'doc_width': 1549.0, 'doc_height': 370.0} }
Install
> python -m pip install amazon-textract-pipeline-pagedimensions
Make sure your environment is setup with AWS credentials through configuration files or environment variables or an attached role. (https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html)
Samples
Add Page dimensions for a local file
sample uses amazon-textract-caller amazon-textract-pipeline-pagedimensions
python -m pip install amazon-textract-caller
from textractpagedimensions.t_pagedimensions import add_page_dimensions
from textractcaller.t_call import call_textract
from trp.trp2 import TDocument, TDocumentSchema
j = call_textract(input_document='<path to some image file>')
t_document: TDocument = TDocumentSchema().load(j)
add_page_dimensions(t_document=t_document, input_document=input_file)
print(t_document.pages[0].custom['PageDimension'])
# output will be something like this:
# {
# 'doc_width': 1544,
# 'doc_height': 1065
# }
Using the Amazon Textact Helper command line tool with PageDimensions
Together with the Amazon Textract Helper and Amazon Textract Response Parser, we can build a pipeline that includes information about PageDimension and Orientation of pages as a short demonstration on the information that is added to the Textract JSON.
> python -m pip install amazon-textract-helper amazon-textract-response-parser amazon-textract-pipeline-pagedimensions
> amazon-textract --input-document "s3://amazon-textract-public-content/blogs/2-pager-different-dimensions.pdf" | amazon-textract-pipeline-pagedimensions --input-document "s3://amazon-textract-public-content/blogs/2-pager-different-dimensions.pdf" | amazon-textract-pipeline --components add_page_orientation | jq '.Blocks[] | select(.BlockType=="PAGE") | .Custom'
{
"PageDimension": {
"doc_width": 1549,
"doc_height": 370
},
"Orientation": 0
}
{
"PageDimension": {
"doc_width": 1079,
"doc_height": 505
},
"Orientation": 0
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for amazon-textract-pipeline-pagedimensions-0.0.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | d0ef5bf05fae3ee207ccef62f9f3d66d554f7c73059595231b91ca86eafa9fee |
|
MD5 | b7a91a67d5efa93e7cfdb9a734629bb2 |
|
BLAKE2b-256 | 8b4c2099af54b30bec6af7d316045eb19d4926bf1134ab5b0b4cd2915157555b |
Hashes for amazon_textract_pipeline_pagedimensions-0.0.4-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca9204d5596ff61bd92b22767a9e826393e41aef77de4b48189c834a228707e9 |
|
MD5 | 692480ed7e8b445afac27e80f8a0ab8f |
|
BLAKE2b-256 | 7583dbc9f374fba3536ffb8ca1641d7ea09422b523bcd030c7e75a2d08aab463 |