Search and Replace in Comments

The PDF-XChange Viewer for End Users
+++ FREE +++

Moderators: TrackerSupp-Daniel, Tracker Support, Chris - Tracker Supp, Vasyl-Tracker Dev Team, Sean - Tracker, Paul - Tracker Supp, Tracker Supp-Stefan, Ivan - Tracker Software

Post Reply
joepierson
User
Posts: 5
Joined: Wed Apr 23, 2014 1:50 pm

Search and Replace in Comments

Post by joepierson » Wed Apr 23, 2014 2:13 pm

Is there a way to search and replace words in multiple comments? I need to replace a word in about 200 comments. Maybe javascript?
thanks!

User avatar
Tracker Supp-Stefan
Site Admin
Posts: 14895
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Search and Replace in Comments

Post by Tracker Supp-Stefan » Wed Apr 23, 2014 3:38 pm

Hello joepierson,

Please modify the string1 and string2 in the code below to the values you need (string1 is the string to be replaced and 2 is the new one you want) and it should work. Please have in mind that this will change the text of typewriter/text box annotations only.

Code: Select all

var annots = this.getAnnots();
annots.length;
for (i = 0; i < annots.length; i++)
{
  if (annots[i].type == "FreeText")
  {
    var str = annots[i].contents;
    var res = str.replace("string1","2String");
    if (str != res) 
    {
      annots[i].contents = res;
    }
  }
}

joepierson
User
Posts: 5
Joined: Wed Apr 23, 2014 1:50 pm

Re: Search and Replace in Comments

Post by joepierson » Wed Apr 23, 2014 7:53 pm

thanks! That worked great except it changed the text font size to 12, is that some default size that I can alter?

joepierson
User
Posts: 5
Joined: Wed Apr 23, 2014 1:50 pm

Re: Search and Replace in Comments

Post by joepierson » Wed Apr 23, 2014 8:28 pm

More info, when I exported the comments and reviewed the objects the /Contents line item was correct but the /RC line item was still the old text.

Ivan - Tracker Software
Site Admin
Posts: 3659
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: Search and Replace in Comments

Post by Ivan - Tracker Software » Wed Apr 23, 2014 11:42 pm

You can use the following script which preserves text formatting:

Code: Select all

var annots = this.getAnnots();
annots.length;
for (i = 0; i < annots.length; i++)
{
  if (annots[i].type == "FreeText")
  {
    var rc = annots[i].richContents;
    if (rc.length > 0)
    {
      var bModified = false;
      for (var j = 0; j < rc.length; j++)
      {
        var str = rc[j].text.replace("string1", "2String");
        if (rc[j].text != str)
        {
          rc[j].text = str;
          bModified = true;
        }
      }
      if (bModified)
        annots[i].richContents = rc;
    }
    else
    {
      var str = annots[i].contents;
      var res = str.replace("string1","2String");
      if (str != res)
      {
        annots[i].contents = res;
      }
    }
  }
}
Please note, it will not replace the text ("string1") if it consists from more than one style.
For example, if "string1" is partly bold, and partly normal (like string1).
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.

joepierson
User
Posts: 5
Joined: Wed Apr 23, 2014 1:50 pm

Re: Search and Replace in Comments

Post by joepierson » Tue Apr 29, 2014 3:05 pm

Thanks! That worked great.

Another question, is it possible (theoretically) to write a java script that extracts the pdf text contained inside a comment text box and transfer the pdf text to the comment box?

I work with schematics (pdf's) and would like to draw text boxes around circuitry, and then have all the parts in the circuit appear in the text box.

User avatar
Tracker Supp-Stefan
Site Admin
Posts: 14895
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Search and Replace in Comments

Post by Tracker Supp-Stefan » Tue Apr 29, 2014 3:30 pm

Hello joepierson,

Have you seen the Edit -> Preferences -> Commenting window and the
Comments Creating Options -> Copy Encircled text into Drawing comment pop-ups checkbox?
Is this what you are after?

Regards,
Stefan

joepierson
User
Posts: 5
Joined: Wed Apr 23, 2014 1:50 pm

Re: Search and Replace in Comments

Post by joepierson » Wed Apr 30, 2014 2:38 pm

No I wasn't aware of that, that is very close to what I need. What I would like to do is parse the encircled text (for very specific text, namely the part numbers in the schematic, and ignore the other text in the encircled area) in javascript and insert it into a typewriter box.

User avatar
Tracker Supp-Stefan
Site Admin
Posts: 14895
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Search and Replace in Comments

Post by Tracker Supp-Stefan » Wed Apr 30, 2014 2:48 pm

Hi Joe,

It should be possible to write a JS that will go through all the text in your document - and if it finds the one you need - create a typewriter annotation out of it. Though I don't think you can write a JS that will do something like the "Copy Encircled text" but then apply extra logic to it and remove unnecessary parts of the encircled text.

Regards,
Stefan

Lazi
User
Posts: 2
Joined: Fri Sep 03, 2021 1:48 pm

Re: Search and Replace in Comments

Post by Lazi » Fri Sep 03, 2021 2:50 pm

Hi!
The need what I have is the same or very similar to subject of this thread. I'm looking for such feature like we have in the MS notepad or MS Word called replace (CTRL + H) only for comments. Important for me is to have highlighted found text to see what I'm changing. That's why script probably is not for me :-(. Is there any function like this?

User avatar
Sean - Tracker
Site Admin
Posts: 52
Joined: Wed Sep 14, 2016 5:42 pm
Location: Leitrim, Ireland

Re: Search and Replace in Comments

Post by Sean - Tracker » Fri Sep 03, 2021 3:56 pm

Hi Lazi,

I'm afraid there is no default feature to replace comment text. However, you can specify in the Search Tool to find only text in comments, as detailed on this page of the manual:

https://help.tracker-software.com/pdfxe ... _ed_2.html

Note that in the Options dropdown menu, you can select only "Include Comments" to search for only the text of comments in documents:

image.png

This will enable you to locate the text - but there is no way to automatically update it.

Hope this help and best regards,
Sean Godley
Technical Writer
Tracker Software Products (Canada) LTD
Sales: +1 (250) 324-1621
Fax: +1 (250) 324-1623

Lazi
User
Posts: 2
Joined: Fri Sep 03, 2021 1:48 pm

Re: Search and Replace in Comments

Post by Lazi » Fri Sep 03, 2021 4:33 pm

Thank you for quick answer.
So, I have to do workaround by exporting all comments and edit them in the notepad :roll:

Post Reply