AWS Textract使用的OCR转换服务没有直接限制PDF页面数量,但存在可以影响OCR转换流程的其他因素,如文档大小和复杂度。
以下是一个示例代码,演示如何使用AWS Textract将PDF文件中的所有页面进行OCR转化,并输出识别出的文本结果:
import boto3
textract = boto3.client('textract')
# Read PDF file from local disk
with open("document.pdf", mode='rb') as file:
file_content = file.read()
# Convert all pages to UTF-8 text
response = textract.detect_document_text(Document={'Bytes': file_content})
for item in response["Blocks"]:
if item["BlockType"] == "LINE":
print(item["Text"])
上述代码使用AWS SDK for Python(boto3)连接并调用AWS Textract服务,在将所有PDF页面转换为OCR文本后输出。