Rename PDF's after splitting

Post Reply
User avatar
Terkelsen
Advanced member
Posts: 298
Joined: Thu Sep 08, 2011 5:08 pm
Contact:

Rename PDF's after splitting

Post by Terkelsen »

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?
jdcl
Newbie
Posts: 2
Joined: Mon Nov 26, 2012 1:20 pm

Rename PDF's after splitting

Post by jdcl »

I'll ask the switch team.
dkelly
TOP CONTRIBUTOR
Posts: 658
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

Rename PDF's after splitting

Post by dkelly »

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
User avatar
Terkelsen
Advanced member
Posts: 298
Joined: Thu Sep 08, 2011 5:08 pm
Contact:

Rename PDF's after splitting

Post by Terkelsen »

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?
User avatar
Terkelsen
Advanced member
Posts: 298
Joined: Thu Sep 08, 2011 5:08 pm
Contact:

Rename PDF's after splitting

Post by Terkelsen »

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.
User avatar
Terkelsen
Advanced member
Posts: 298
Joined: Thu Sep 08, 2011 5:08 pm
Contact:

Rename PDF's after splitting

Post by Terkelsen »

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
tz8
Member
Posts: 84
Joined: Mon Aug 13, 2012 12:56 pm

Rename PDF's after splitting

Post by tz8 »

please try this crude hack:



var pgnum = ("000" + parseInt(pgstr.left(3),10)).match(/(...)$/);
User avatar
Terkelsen
Advanced member
Posts: 298
Joined: Thu Sep 08, 2011 5:08 pm
Contact:

Rename PDF's after splitting

Post by Terkelsen »

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
dkelly
TOP CONTRIBUTOR
Posts: 658
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

Rename PDF's after splitting

Post by dkelly »

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(/(...)$/);

User avatar
Terkelsen
Advanced member
Posts: 298
Joined: Thu Sep 08, 2011 5:08 pm
Contact:

Rename PDF's after splitting

Post by Terkelsen »

First it was great, now is's perfect :-) Thank's a lot to both Dwight and tz8 (whoever you are).
Post Reply