【问题标题】:Replacing Text in a PDF with Aspose PDF Cloud using Python使用 Python 使用 Aspose PDF Cloud 替换 PDF 中的文本
【发布时间】:2021-03-08 08:27:38
【问题描述】:

我一直在尝试使用 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']}

请指教

【问题讨论】:

  • 您可以检查您的云存储以验证文件路径,它将解决问题。

标签: python pdf aspose aspose.pdf


【解决方案1】:

这个问题可以解决,

替换

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

remote_name = 'dummy.pdf'

【讨论】:

  • 所以这意味着您将文件上传到云存储根目录而不是“/content/sample_data”文件夹。
  • 是的,但我真的不明白添加不同的路径如何解决问题
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-02-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多