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

Replacing Text in a PDF with Aspose PDF Cloud using Python

我一直在尝试使用 Aspose PDF Cloud

替换 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']}

请指教

问题可以通过

解决

正在替换

remote_name = '/content/sample_data/dummy.pdf'

remote_name = 'dummy.pdf'