Please follow the steps given below to Find and Replace Text in PDF file using Aspose.PDF Cloud SDK for Python.
For more information, please visit the following blog Find and Replace Text in PDF using Python.
Please follow the steps given below to Find and Replace Text in PDF file using Aspose.PDF Cloud SDK for Python.
For more information, please visit the following blog Find and Replace Text in PDF using Python.
This Gist contains code snippets regarding Find and Replace Text in PDF using Aspose.PDF Cloud SDK for Python |
def findAndReplaceText(): | |
try: | |
#Client credentials | |
client_secret = "1c9379bb7d701c26cc87e741a29987bb" | |
client_id = "bbf94a2c-6d7e-4020-b4d2-b9809741374e" | |
#initialize PdfApi client instance using client credetials | |
pdf_api_client = asposepdfcloud.api_client.ApiClient(client_secret, client_id) | |
# create PdfApi instance while passing PdfApiClient as argument | |
pdf_api = PdfApi(pdf_api_client) | |
#source image file | |
input_file = 'URL2PDF.pdf' | |
# Replacement text properties | |
text_Replace_Request = asposepdfcloud.TextReplaceListRequest | |
{ | |
"TextReplaces": [ | |
{ | |
"OldValue": "Productivity", | |
"NewValue": "Increased Productivity", | |
# "Regex": True, | |
"TextState": { | |
"FontSize": 0, | |
"Font": "Arial", | |
"ForegroundColor": { | |
"A": 0, | |
"R": 252, | |
"G": 240, | |
"B": 3 | |
}, | |
"BackgroundColor": { | |
"A": 0, | |
"R": 252, | |
"G": 3, | |
"B": 248 | |
}, | |
"FontStyle": "Regular" | |
}, | |
"Rect": { | |
"LLX": 0, | |
"LLY": 0, | |
"URX": 0, | |
"URY": 0 | |
} | |
} | |
], | |
"DefaultFont": "Arial", | |
"StartIndex": 0, | |
"CountReplace": 0 | |
} | |
# call the API to replace text in PDF document | |
response = pdf_api.post_document_text_replace(name = input_file, text_replace = text_Replace_Request) | |
print(response) | |
# print message in console (optional) | |
print('Text successfully Replaced in PDF !') | |
except ApiException as e: | |
print("Exception while calling PdfApi: {0}".format(e)) | |
print("Code:" + str(e.code)) | |
print("Message:" + e.message) |