Replace Text in PDF using Python returns 0 match

Hello, I wanted to try a basic text replace but I didn’t manage to make it works. The PDF is generated by Adobe Illustrator. I tried with various standard and compatibility when saving the file without success.

The response: {‘code’: 200, ‘matches’: 0, ‘status’: ‘OK’}

The code used (Python): https://pastebin.com/F9YZHyDk

The PDF:
sample.pdf (594.5 KB)
Adobe PDF Preset: [PDF/X-4:2008]
Standard: PDF/X-4:2010
Compatibility: Acrobat 7 (PDF 1.6)

@repar

It seems your input PDF document is non searchable(image only) PDF. We tried to search and replace text in your sample PDF with the following steps, but we are unable to find any text.

Steps to Replace Text in PDF using Python

  1. Create an aspose.cloud account and get Client Id and Client Secret
  2. Install Aspose.PDF Cloud SDK for Python from PIP
  3. Create a script File for the code and import Aspose.PDF Cloud modules
  4. Upload your sample PDF file to the Cloud Storage
  5. Find and Replace occurrences of Text in PDF document

Steps to Replace Text in PDF using Python

# Import Modules
import os
import asposepdfcloud
from asposepdfcloud.apis.pdf_api import PdfApi

# Get Client ID and Secret from https://cloud.aspose.com
pdf_api_client = asposepdfcloud.api_client.ApiClient('xxxxxxxxxxxxxxxxxxxxxxxxxx','xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx')

pdf_api = PdfApi(pdf_api_client)
local_filename = 'sample.pdf'
remote_file = 'sample.pdf'

#upload PDF file to storage
pdf_api.upload_file(remote_file,local_filename)

#Replace Text
text_replace1 = asposepdfcloud.models.TextReplace(old_value='Client',new_value='Customer',regex='true')
text_replace_list = asposepdfcloud.models.TextReplaceListRequest(text_replaces=[text_replace1])

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


Please note even Adobe Acrobat Pro XI is unable to search text from your sample PDF document.