Wonder if anybody can help me with this one?
I have several hundred PDF spreads that needs to be split into single pages. The Split PDF function in Switch does that. So far so good.
All the spreads are named in a way that means that segment 10-12 of the filename is a three digit number of the first page in the spread. Say, the file is named 201109011042.pdf this means that this spread holds the pages 042 AND 043.
After splitting the spread I would like the resulting single pages to be named:
201109011042.pdf
and
201109011043.pdf
In other words the first page should keep the original name and the second file named the sum of "the original name +1" so to speak.
Any ideas?
Rename PDF's after splitting
Rename PDF's after splitting
I'll ask the switch team.
-
- TOP CONTRIBUTOR
- Posts: 628
- Joined: Mon Nov 29, 2010 8:45 pm
- Location: Alpharetta GA USA
- Contact:
Rename PDF's after splitting
Here's the flow I created to perform the split and rename as you described.
The rename element has the following settings
Action 1: Search and replace
Act on: Filename proper
Search for: text with variable: [Job.NameProper:Segment=10-15]
Replace by: script defined
var pgstr = job.getNameProper().right(5);
var pgnum = parseInt(pgstr.left(3),10);
var seqnum = parseInt(pgstr.right(1),10)-1;
pgnum += seqnum;
pgnum.toString();
Dwight Kelly
Apago, Inc.
dkelly@apago.com
The rename element has the following settings
Action 1: Search and replace
Act on: Filename proper
Search for: text with variable: [Job.NameProper:Segment=10-15]
Replace by: script defined
var pgstr = job.getNameProper().right(5);
var pgnum = parseInt(pgstr.left(3),10);
var seqnum = parseInt(pgstr.right(1),10)-1;
pgnum += seqnum;
pgnum.toString();
Dwight Kelly
Apago, Inc.
dkelly@apago.com
Rename PDF's after splitting
Hi Dwight,
Tanks a lot. This was just what I was looking for. Only one little thing missing, however. I would very much like if it was possible that the page number was always 3 digits. Rather than 20110901142 I would like it to be 201109011042. Would that be hard to add?
Tanks a lot. This was just what I was looking for. Only one little thing missing, however. I would very much like if it was possible that the page number was always 3 digits. Rather than 20110901142 I would like it to be 201109011042. Would that be hard to add?
Rename PDF's after splitting
Oh, now that I come to think of it the first of the three digits will always be the same for both pages in a spread, since the first page will always have an even number. I just changed "right(5)" to "right(4)" which seems to do the trick.
Rename PDF's after splitting
Hmm, and the again. This last solution will not create three digits for the pages from 1-9. 201109011004 becomes 20110901104 and 20110901105 rather than 201109011004 and 201109011005
Rename PDF's after splitting
please try this crude hack:
var pgnum = ("000" + parseInt(pgstr.left(3),10)).match(/(...)$/);
var pgnum = ("000" + parseInt(pgstr.left(3),10)).match(/(...)$/);
Rename PDF's after splitting
Hi tz8,
Excuse my ignorance, but I'm not quite sure how to use the code you suggest. I have tried to replace line 2 in Dwight's script with your code making it look like this:
var pgstr = job.getNameProper().right(5);
var pgnum = ("000" + parseInt(pgstr.left(3),10)).match(/(...)$/);
var seqnum = parseInt(pgstr.right(1),10)-1;
pgnum += seqnum;
pgnum.toString();
That does indeed add the missing "0" at the right place in the filename. However, it adds "0" and "1" at the end of the filenames rather than calculating the value of the last segment +0 and +1.
This way the filenames ends up as
2011090110040 and 2011090110041
rather than the wanted
201109011004 and 201109011005
Excuse my ignorance, but I'm not quite sure how to use the code you suggest. I have tried to replace line 2 in Dwight's script with your code making it look like this:
var pgstr = job.getNameProper().right(5);
var pgnum = ("000" + parseInt(pgstr.left(3),10)).match(/(...)$/);
var seqnum = parseInt(pgstr.right(1),10)-1;
pgnum += seqnum;
pgnum.toString();
That does indeed add the missing "0" at the right place in the filename. However, it adds "0" and "1" at the end of the filenames rather than calculating the value of the last segment +0 and +1.
This way the filenames ends up as
2011090110040 and 2011090110041
rather than the wanted
201109011004 and 201109011005
-
- TOP CONTRIBUTOR
- Posts: 628
- Joined: Mon Nov 29, 2010 8:45 pm
- Location: Alpharetta GA USA
- Contact:
Rename PDF's after splitting
The problem was mixing string and integer types.
var pgstr = job.getNameProper().right(5);
var pgnum = parseInt(pgstr.left(3),10);
var seqnum = parseInt(pgstr.right(1),10)-1;
pgnum += seqnum;
("000" + pgnum.toString()).match(/(...)$/);
var pgstr = job.getNameProper().right(5);
var pgnum = parseInt(pgstr.left(3),10);
var seqnum = parseInt(pgstr.right(1),10)-1;
pgnum += seqnum;
("000" + pgnum.toString()).match(/(...)$/);
Rename PDF's after splitting
First it was great, now is's perfect
Thank's a lot to both Dwight and tz8 (whoever you are).
