当我尝试解析通过 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']
这给了我错误,请求具有不受支持的文档格式。
detect_document_text() 是一个同步 API,仅支持 PNG 或 JPG 图像。对于 PDF,它只能支持单页 PDF。
如果您想处理 PDF 文件,您应该使用名为 start_document_text_detection() 的异步 API。
Textract 同步 API 现在已经支持单页 PDF 一段时间了。
因此,您可以预先分割文档并使用同步 API,或者如果直接使用文件,则使用异步 API。