Skip to main content

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


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

File details

Details for the file amazon-textract-pipeline-pagedimensions-0.0.3.tar.gz.

File metadata

  • Download URL: amazon-textract-pipeline-pagedimensions-0.0.3.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.5

File hashes

Hashes for amazon-textract-pipeline-pagedimensions-0.0.3.tar.gz
Algorithm Hash digest
SHA256 513d4bac51b9b5aee02d1bc9d198606fb689e9f3ff73d8184c4d76723316de1c
MD5 d45ff4928772e00bd5cb6e84e3f8df5e
BLAKE2b-256 d67cfb24e86180f58e2094548418e80b662d3f9463192835889a9949888f704c

See more details on using hashes here.

File details

Details for the file amazon_textract_pipeline_pagedimensions-0.0.3-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for amazon_textract_pipeline_pagedimensions-0.0.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 2e6d7149083845b6edfc80204d9c78bece859ed74101bba686c85767fab725f8
MD5 271a480db532b334b96ec1fc2f8882f7
BLAKE2b-256 dea6f86df2234881047bbcfa842b2afcb1b28a5ad8e962e84884575027232923

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page