【问题标题】:Using AWS Textract for processing PDF使用 AWS Texttract 处理 PDF
【发布时间】:2020-10-08 10:52:57
【问题描述】:

我想使用 Textract OCR 服务从 pdf 文件中读取文本。我有一个问题,因为我想在本地做,没有 S3 桶。我对图像文件进行了测试,效果很好,但不适用于 PDF 文件。

这是我得到错误的代码:

response = textract.start_document_text_detection(DocumentLocation="sample2.pdf")

错误:

Invalid type for parameter DocumentLocation, value: sample2.pdf, type: <class 'str'>, valid types: <class 'dict'>

代码2:

response = textract.start_document_text_detection(DocumentLocation={"name":"sample2.pdf"})

错误:

Unknown parameter in DocumentLocation: "name", must be one of: S3Object

代码3:

response = textract.start_document_text_detection(Document={'Bytes': "sample2.pdf"})

错误:

Unknown parameter in input: "Document", must be one of: DocumentLocation, ClientRequestToken, JobTag, NotificationChannel, OutputConfig

我该怎么办,有没有办法让 Textract 可以在没有 s3 的情况下处理 PDF 文档?

【问题讨论】:

标签: python ocr amazon-textract


【解决方案1】:

您的问题的简短回答是“否”。

Textract 仅适用于 S3 的输入。 y\您将需要遵循此处 boto3 文档中为服务描述的预期输入格式: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/textract.html#Textract.Client.start_document_text_detection

本质上,服务需要结构化输入,您需要根据他们的规范正确填写。这是 boto3 期望的 DocumentLocation 字典输入。

DocumentLocation={
    'S3Object': {
        'Bucket': 'string',
        'Name': 'string',
        'Version': 'string'
    }
}

我目前也遇到了一些类似的问题,使其在 boto3 中也能正常工作,但我会继续通过文档工作,看看我能弄清楚什么。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-15
    • 2023-02-25
    • 2018-08-17
    • 2012-04-04
    相关资源
    最近更新 更多