使用 Amazon Textract 时不受支持的文档格式,

问题描述 投票:0回答:2

当我尝试解析通过 amazon s3 访问的 pdf 文件时,它给我一个错误,请求具有不受支持的文档格式。

我正在使用 Amazon texttract 和 boto3。当我尝试解析通过 amazon s3 访问的 pdf 文件时,它给我一个错误,请求不受支持 文档格式。我对此相当陌生,在 textract 的文档中提到确实支持 pdf 文件。

这是我正在使用的代码。

import boto3
textractClient = boto3.client('textract',region_name='us-east-1')
response = textractClient.detect_document_text(
        Document={'S3Object': {'Bucket': 'bucketName', 'Name': 'filename.pdf'}})
blocks = response['Blocks']

这给了我错误,请求具有不受支持的文档格式。

python python-3.x amazon-textract
2个回答
38
投票

detect_document_text() 是一个同步 API,仅支持 PNG 或 JPG 图像。对于 PDF,它只能支持单页 PDF。

如果您想处理 PDF 文件,您应该使用名为 start_document_text_detection() 的异步 API。

https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/textract.html#Textract.Client.start_document_text_detection


4
投票

Textract 同步 API 现在已经支持单页 PDF 一段时间了

因此,您可以预先分割文档并使用同步 API,或者如果直接使用文件,则使用异步 API。

参考:https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/textract/client/start_document_text_detection.html

© www.soinside.com 2019 - 2024. All rights reserved.