Skip to main content
New Participant
September 20, 2021
Answered

search a text string and replace with another text in multiple pdf's (no manual)

  • September 20, 2021
  • 2 replies
  • 2600 views

Hi,

 

im very new to PDF scripting. I just want to write an automated script which can search a simple text string and replace it with an another text string in multiple PDF document. Can somebody help me on this? i do not want to do it manually for more than 300 PDF's. Atleast, 1 example of scripting will help me to build the script or anyother way to deal with it.

This topic has been closed for replies.
Correct answer try67

You keep calling it a field, but I'm not sure that's what it really is... Can you see it when you go to Tools - Prepare Form mode? If not, then it's static text and can only be removed by a script (using Redaction) and new text can be added in its place. However, the new text won't be tagged.

2 replies

New Participant
September 22, 2021

If there is no solution of this query then i think Acrobat is very limited. We need to look something beyond from this.

Legend
September 22, 2021

Yes, Acrobat doesn't do this. Acrobat scripting is extremely limited and simple, the main API is for C++ plug-ins. 

However, you need to understand that a PDF is not a Word document; Search and Replace is a very dubious and difficult concept for PDF files because there is no text flow.

try67
Community Expert
Community Expert
September 20, 2021

Are you referring to static text in the file? If so, a script can't do that. The closest it can get is to overwrite the old text with new one, but it can't know what font the old text was, or what color, or what's the background color behind it. Also, it can't move any of the text around it, so if the old text is not the same length as the new one it will look odd (as the font sizes won't match), or some text will get overwritten. In short, it's not very doable with a script.

New Participant
September 21, 2021

No, it's not a static field in the PDF. It's a tagged hidden text field in the PDF. If we do manual "find" and "replace with" then it's working good for me. But, i do not want to do it manually so i want to write a script to find the text field in the PDF or Multiple PDF's and get it replaced. Please find the below attached taaged text hidden field screenshot.

 

 

Let's say the hidden tagged text field is NAME, the script will find the text field NAME and will replace the text field as "FIRSTNAME", That's it.

We need 1 script example atleast for 1 PDF doc change, we can try in multiple PDF's later.

Legend
September 21, 2021

There is nothing in scripting to do this. There are no functions to change static text at all. I agree with what was said before.