Numbering files after pdf split

Post Reply
pfischer
Member
Posts: 43
Joined: Tue May 14, 2013 4:57 pm

Numbering files after pdf split

Post by pfischer »

Hello togehter,

I hope you can help me.

A multi-page PDF document is divided into individual pages. The individual documents should then be numbered consecutively. However, the numbering should start at 2 and should always be counted 2 higher.
I tried to assign a start value and a count value in the switch variable "Counter", but without success.

Ex..:
Source document "name.pdf" (contains any number of pages)

Result (Numbering starts with 2 and always counts up 2. Each document contains only one page):
002_name.pdf
004_name.pdf
006_name.pdf
...

Can this be realized with the "Split PDF" flow element?

Thanks for your help.
Many greetings,
Peter Fischer
Media asset and production specialist
Group Communications / System Operations
Phoenix Contact GmbH & Co. KG
www.phoenixcontact.com
pfischer
Member
Posts: 43
Joined: Tue May 14, 2013 4:57 pm

Re: Numbering files after pdf split

Post by pfischer »

Update:

I have solved the problem with renaming and calculation.

001.pdf -> 2.pdf
002.pdf -> 4.pdf
003.pdf -> 6.pdf

I have done a calculation on the filename (*2). But then I loose the leading zeros.
Media asset and production specialist
Group Communications / System Operations
Phoenix Contact GmbH & Co. KG
www.phoenixcontact.com
freddyp
Advanced member
Posts: 1022
Joined: Thu Feb 09, 2012 3:53 pm

Re: Numbering files after pdf split

Post by freddyp »

You can also add the leading zeroes with the "Rename job" element. Use "Search and replace" in this way:
Search: (\d+)(.*)
Replace: 00\1\2

This means makes two groups, the first one with one or more digits at the beginning and then the rest. Replace this with 2 zeroes followed by the contents of group 1 and group 2. The result will always add 2 zeroes but perhaps only 1 has to be added or even none at all. So we rename again to get rid of zeroes that make the number of digits higher than 3.

Search: (0*)(\d{3})(.*)
Replace: \2\3

This means make three groups, one with zero or more zeroes, three digits and then the rest. And replaces with groups 2 and 3.

The two renames can be done inside the same "Rename job" and make sure to use "Define regular expression", do not paste the regular expressions in the property field because then they will be used as strings, not as regular expressions!!
patej
Member
Posts: 79
Joined: Sun Nov 25, 2012 12:15 pm

Re: Numbering files after pdf split

Post by patej »

If you have Scripting Module and you want to ensure that there are always e.g. at least 3 numbers (001,002, ... 011 etc), you can use script expression in Rename job:

Code: Select all

var lengthRequired = 3;
var regex = /^(\d+)/;
var name = job.getNameProper();
name.match(regex);
var nr = regex.capturedTexts[1];
var zeroes = lengthRequired-nr.length;
for(var j=0;j<zeroes;j++){		
	name = '0'+name;
}
name
––> this adds '00' to '1.pdf', but '0' to '02.pdf' so those become 001.pdf and 002.pdf. The logic can be extended to ensure e.g. 00001, 00002 by changing lengthRequired value to 5.
Post Reply