Hi all,
What I would like to achieve is to batch change the code below in every pdf in a given directory (each pdf is uncompressed so that can be easily edited).
An example of the javascript code:
if (this.hostContainer) { try { this.hostContainer.postMessage(['newPage', 'pp_216', 15259]); } catch(e) { console.println(e); } };
The portion pp_216 can vary and and the number 216 is just an example. After pp_ there can be two possibilities: (1) an ordinary number (Arabic), e.g. 1, 2 216 etc. If this is the case, I would like to subtract 16 from this number. For example:
this.zoomType = zoomtype.pref;
this.pageNum = 200;
Second option is a Roman number
if (this.hostContainer) { try { this.hostContainer.postMessage(['newPage', 'pp_v', 15259]); } catch(e) { console.println(e); } };
In this case I would like to have this Roman numbered change into Arabic and then take 2 of it.
For example:
this.zoomType = zoomtype.pref;
this.pageNum = 3;
At first I tried to use bash, but it seems that it does not allow for what I am looking for. Perl supports Roman numbers [no link because I do not have 5 points] and regex. When it comes to regex before I was told that it would not be good idea to use it, I had come up with this piece of code:
use warnings; use strict; our @array = `find -P $path -type f -name \'*.pdf\'`; foreach my $p (@array){ open(my $source, $p) or die "Cannot open a file"; while(my $line = <$source>){ if($line =~ (?<=pp_)\d+(?:\'\d+)?){
but it is possibly buggy and supports only Arabic (0-9) numbers.
All the code above is also in attached .txt since I cannot set the correct formatting. In an attachment you can also find sample 'unpacked' pdf with two entries edited by me (line 6242 and 6246) to show what I am looking for.