【问题标题】:Python - Google Cloud Document AI API- Not reading the whole .pdf filePython - Google Cloud Document AI API - 不读取整个 .pdf 文件
【发布时间】:2021-05-10 14:58:51
【问题描述】:

我正在尝试使用 Google Document AI API 读取存储在 gcs i Python 中的 pdf,并将 pdf 中的文本作为字符串返回。我不希望解析器读取表格和图像,因为我只对文本感兴趣。下面是我用来解析文档的代码。

def parse_invoice_1(project_id='xxx',
     input_uri='gs://xxx/file.pdf'):


client = documentai.DocumentUnderstandingServiceClient.from_service_account_json('json_file')

gcs_source = documentai.types.GcsSource(uri=input_uri)


input_config = documentai.types.InputConfig(
    gcs_source=gcs_source, mime_type='application/pdf')



key_value_pair_hints = [
    documentai.types.KeyValuePairHint(key='Emergency Contact',
                                      value_types=['NAME']),
    documentai.types.KeyValuePairHint(
        key='Referred By')
]

# Setting enabled=True enables form extraction
form_extraction_params = documentai.types.FormExtractionParams(
enabled=True,
key_value_pair_hints=key_value_pair_hints)


parent = 'projects/{}/locations/us'.format(project_id)
request = documentai.types.ProcessDocumentRequest(
    parent=parent,
    input_config=input_config,
    form_extraction_params=form_extraction_params)

document = client.process_document(request=request)
return(format(document.text))

string=parse_invoice_1()

pdf 文件大约有 410 页。但是上面的解析代码只读取了6页。我错过了什么吗?

【问题讨论】:

    标签: google-api-python-client pdf-parsing cloud-document-ai


    【解决方案1】:

    使用process_document() 时,每个请求的页数限制为 10 个。为了让您一次处理更多页面,我建议使用 batch_process_documents()。 batch_process_documents() 异步处理您的文档,每个请求最多可以处理 500 页。

    对于表参考检查它here

    批处理的代码示例可见Large file offline processing (python).

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-11-20
      • 2022-08-03
      • 1970-01-01
      • 2019-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多