Copy link to clipboard
Copied
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.
1 Correct answer
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
You are correct here that the field is not showing in prepare form mode. By using the redact tool, it's able to search the text. The new replaced text is not requied to tag it as per my use case. So, im good in there.
But, i dnt want to do it manually in 300 pdf's, need some kind of automation to apply it in multiple pdf's. so, i am looking for any pdf javascript to handle it.
Copy link to clipboard
Copied
Redaction can be automated, but it's not simple. You will need to use a script to go over all the words in the file, adding a Redaction annotation over any matches. Alternatively, you can use the Search & Remove Text command, but that can't be scripted.
Copy link to clipboard
Copied
Just to clarify, that command can be included in an Action, though, and executed over multiple files.
Copy link to clipboard
Copied
can you please give me a working example in an Action??, just steps would be fine...
Copy link to clipboard
Copied
An example of what? How to do it with a script? That will require developing this script in full.
If you're interested in something like that I can do it for a fee. You can contact me privately via [try6767 at gmail.com] to discuss it further.
Copy link to clipboard
Copied
If there is no solution of this query then i think Acrobat is very limited. We need to look something beyond from this.
Copy link to clipboard
Copied
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.

