I am using pdftk to burst pdf in different pages. This utility ("pdftk <pdf filename> burst") produces single page pdf for every page of input pdf. Name of out pdf is like pg_{x}.pdf. where {x} is page number with leading zeros to make total length as 4 (if it is less than 4).

Example:

>> pdftk test.pdf burst
>> ls
pg_0001.pdf pg_0002.pdf pg_0003.pdf pg_0004.pdf
Since I have to work on these files; I need to add leading zeros to integer to make a string with defined quantity of digits. I found buildin function zfill to add zeros on the left to a string. The best part of using this is that it understands about plus and minus signs.

Usage: string.zfill(final string length)

Example:
>>> print str(1).zfill(5)
00001
>>> print str(14).zfill(3)
014
>>> print str(-11).zfill(3)
-11
>>> print str(-11).zfill(6)
-00011
>>> print '12'.zfill(5)
00012
>>> print '-3.14'.zfill(7)
-003.14
>>> print '3.14159265359'.zfill(5)
3.14159265359


Subscribe - To get an automatic feed of all future posts subscribe here, or to receive them via email go here and enter your email address in the box. You can also like us on facebook and follow me on Twitter @akashag1001.