Hi,
I'd like to be able to change automatically the author or subject of some hundred notes!! Is it possible to search and replace author and subject within notes ?
Thanks
Search and Replace author and subject within notes
Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Paul - PDF-XChange, Vasyl - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange
-
francois maurice
- User
- Posts: 102
- Joined: Sat Sep 29, 2012 5:38 am
-
Ivan - Tracker Software
- Site Admin
- Posts: 3603
- Joined: Thu Jul 08, 2004 10:36 pm
Re: Search and Replace author and subject within notes
Yes, it is possible, but you have to use a JavaScript script.
Here you can find a sample, and modify it for your purpose:
You can open JS console (use Ctlr+J shortcut) and run this script there.
HTH
Here you can find a sample, and modify it for your purpose:
Code: Select all
function ReplaceAuthor(oldAuthor, newAuthor)
{
this.syncAnnotScan();
for (var i = 0; i < this.numPages; i++)
{
var annots = this.getAnnots(i);
for (var j = 0; j < annots.length; j++)
{
if (annots[j].author == oldAuthor)
annots[j].author = newAuthor;
}
}
}
function ReplaceSubject(oldSubject, newSubject)
{
this.syncAnnotScan();
for (var i = 0; i < this.numPages; i++)
{
var annots = this.getAnnots(i);
for (var j = 0; j < annots.length; j++)
{
if (annots[j].subject == oldSubject)
annots[j].subject = newSubject;
}
}
}
//
ReplaceAuthor("old", "new");
ReplaceSubject("oldSubj", "Subj");
HTH
PDF-XChange Co Ltd. (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.
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.
-
francois maurice
- User
- Posts: 102
- Joined: Sat Sep 29, 2012 5:38 am
Re: Search and Replace author and subject within notes
Thanks for the tip.
The script works well with 'Notes' or 'Comments', but in fact I'm using 'Highlighted Text' (I'm not in English since I'm using the french interface) by clicking on the 'blue T on yellow' icon.
Surely it has something to do with 'GetAnnots' method ! Can you tell me which method to use with 'Highlighted Text' ?
Thanks a lot !
The script works well with 'Notes' or 'Comments', but in fact I'm using 'Highlighted Text' (I'm not in English since I'm using the french interface) by clicking on the 'blue T on yellow' icon.
Surely it has something to do with 'GetAnnots' method ! Can you tell me which method to use with 'Highlighted Text' ?
Thanks a lot !
-
Ivan - Tracker Software
- Site Admin
- Posts: 3603
- Joined: Thu Jul 08, 2004 10:36 pm
Re: Search and Replace author and subject within notes
Highlight Text is an annotation too and should works ok.
Can you send me you document by email for checking? (please use ivan@tracker-software.com)
Can you send me you document by email for checking? (please use ivan@tracker-software.com)
PDF-XChange Co Ltd. (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.
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.
-
francois maurice
- User
- Posts: 102
- Joined: Sat Sep 29, 2012 5:38 am
Re: Search and Replace author and subject within notes
Thanks Ivan for the JS code. It works well and you save me many hours of boring job.
For those who are interested, this is the new code from Ivan Poberezhnyk :
Tanks again Ivan,
François Maurice
For those who are interested, this is the new code from Ivan Poberezhnyk :
Code: Select all
function ReplaceSubject(oldSubject, newSubject)
{
this.syncAnnotScan();
var numReplacements = 0;
for (var i = 0; i < this.numPages; i++)
{
var annots = this.getAnnots(i);
if (annots != null)
{
for (var j = 0; j < annots.length; j++)
{
if (annots[j].subject == oldSubject)
{
annots[j].subject = newSubject;
numReplacements++;
}
}
}
}
console.println("Replacements: " + numReplacements);
}
//
ReplaceSubject("oldSubject", "newsSubject");François Maurice
-
Will - Tracker Supp
- Site Admin
- Posts: 6815
- Joined: Mon Oct 15, 2012 9:21 pm
Re: Search and Replace author and subject within notes
Hi François,
thanks for posting the updated script!
thanks for posting the updated script!
If posting files to this forum, you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded.
Thank you.
Best regards
Will Travaglini
Tracker Support (Europe)
Tracker Software Products Ltd.
http://www.tracker-software.com
Thank you.
Best regards
Will Travaglini
Tracker Support (Europe)
Tracker Software Products Ltd.
http://www.tracker-software.com