1

I've been trying to replace text from a PDF file using Aspose PDF Cloud

!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)

However, when I try running the above code it yields an error

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'})

Not sure why this error pops up after a successful upload {'errors': [], 'uploaded': ['dummy.pdf']}

Please Advise

1
  • 1
    You may check your cloud storage to verify the file path, it will resolve the issue. Commented Mar 9, 2021 at 5:13

1 Answer 1

1

The issue can be solved by,

Replacing

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

With

remote_name = 'dummy.pdf'
Sign up to request clarification or add additional context in comments.

2 Comments

So it means you uploaded the file to cloud storage root instead of "/content/sample_data" folder.
Yeah but I don't really see how adding a different path solves the issue

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.