Bug 50914

Summary: pdfseparate - error checking for destFileName precludes use of valuable sprintf options
Product: poppler Reporter: Joe Mooring <joe>
Component: utilsAssignee: poppler-bugs <poppler-bugs>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: medium    
Version: unspecified   
Hardware: Other   
OS: Linux (All)   
Whiteboard:
i915 platform: i915 features:
Attachments: allow zero-padded pagespecs

Description Joe Mooring 2012-06-09 08:01:32 UTC
When using pdfseparate, if the first page number and the last page number are not equal, the destination file name is checked to make sure it includes %d.

This error checking is far too restrictive -- it precludes the use of many useful sprintf format options.

For example, I would like to separate a 100 page pdf file as follows:
destination-001.pdf
destination-002.pdf
...
destination-099.pdf
destination-100.pdf

I should be able to use this standard sprintf syntax:
pdfseparate source.pdf destination-%03d.pdf

However, since destFileName does not contain %d, this command throws an error:
"Error: 'file-%03d.pdf' must contain '%d' if more than one page should be extracted

To work around this, I'm adding %%d to the end of the file name (to satisfy the error checking requirement), then renaming all the files afterwards:
pdfseparate source.pdf destination-%03d.pdf.%%d

Options:
a) Refine the error checking to handle all sprintf format options
b) Remove the error checking
Comment 1 Thomas Freitag 2012-06-09 11:24:41 UTC
Nice idea!
Feel free to implement and upload a patch fot it!
Comment 2 Daniel Kahn Gillmor 2013-09-16 18:21:56 UTC
Created attachment 85930 [details] [review]
allow zero-padded pagespecs

This is a pretty dumb patch that enables the use of %01d, %02d, ... up to %09d.  If you have a billion-page PDF it won't let you zero-pad it properly :P

It doesn't change the current default non-zero-padded behavior of %d (i don't know if anyone is relying on that) and it doesn't auto-detect what the size of the zero-padding should be.

The patch was written to apply to 0.22-5, i think.
Comment 3 Albert Astals Cid 2013-09-25 18:39:32 UTC
Looks, ok to me. Thomas, what's your opinion?
Comment 4 Thomas Freitag 2013-09-26 07:29:27 UTC
(In reply to comment #3)
> Looks, ok to me. Thomas, what's your opinion?

Looks ok for me, too!
Comment 5 Albert Astals Cid 2013-10-02 18:36:55 UTC
Commited, will be available in poppler 0.26

Thanks for your patience :-)

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.