Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

New Here ,
Sep 20, 2021 Sep 20, 2021

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.

TOPICS
Acrobat SDK and JavaScript
2.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Sep 21, 2021 Sep 21, 2021

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.

Translate
Community Expert ,
Sep 20, 2021 Sep 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 20, 2021 Sep 20, 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.

 

AnupKumar5CCF_0-1632202171978.pngexpand image

 

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 21, 2021 Sep 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. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 21, 2021 Sep 21, 2021

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 21, 2021 Sep 21, 2021

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.

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 22, 2021 Sep 22, 2021

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 22, 2021 Sep 22, 2021

Just to clarify, that command can be included in an Action, though, and executed over multiple files.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 22, 2021 Sep 22, 2021

can you please give me a working example in an Action??, just steps would be fine...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 22, 2021 Sep 22, 2021
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 21, 2021 Sep 21, 2021

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 22, 2021 Sep 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines