使用Python将PDF中的文本替换为Aspose PDF Cloud

2024-09-30 12:13:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在尝试使用asposepdfcloud替换PDF文件中的文本

!pip install asposepdfcloud

import os 
import asposepdfcloud 
from asposepdfcloud.apis.pdf_api import PdfApi

pdf_api_client = asposepdfcloud.api_client.ApiClient(
    app_key='xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
    app_sid='xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxxx')

pdf_api = PdfApi(pdf_api_client) 
filename = '/content/sample_data/dummy.pdf' 
remote_name = '/content/sample_data/dummy.pdf'

pdf_api.upload_file(remote_name,filename) 

text_replace1 = asposepdfcloud.models.TextReplace(old_value='PDF',new_value='XXX',regex='true') 
text_replace_list = asposepdfcloud.models.TextReplaceListRequest(text_replaces=[text_replace1]) 

response = pdf_api.post_document_text_replace(remote_name, text_replace_list) 
print(response)

但是,当我尝试运行上面的代码时,它会产生一个错误

ApiException: (404)
Reason: Not Found
HTTP response headers: HTTPHeaderDict({'Date': 'Mon, 08 Mar 2021 08:21:44 GMT', 'Content-Length': '0', 'Connection': 'keep-alive', 'Server': 'Kestrel', 'Strict-Transport-Security': 'max-age=2592000'})

不确定为什么在成功上传后会弹出此错误{'errors': [], 'uploaded': ['dummy.pdf']}

请告知


Tags: textnameimportclientapiapppdfremote

热门问题