Skip to content

Syntax for merging entire PDF files #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rbro opened this issue May 31, 2013 · 22 comments
Closed

Syntax for merging entire PDF files #11

rbro opened this issue May 31, 2013 · 22 comments

Comments

@rbro
Copy link

rbro commented May 31, 2013

If I needed to merge the entire a1.pdf and a2.pdf into b.pdf, is the best way to do it with:

qpdf --empty --pages a1.pdf 1-z a2.pdf 1-z -- b.pdf

Is there a way it can be called without specifying 1-z for each page? It would ideal if I could call it with something like:

qpdf --empty --pages a1.pdf a2.pdf -- b.pdf

which would then allow me to call it with wildcards like:

qpdf --empty --pages a*.pdf -- b.pdf

Thanks for your help.

@qpdf
Copy link
Collaborator

qpdf commented May 31, 2013

I'm afraid there isn't a way to do it without the 1-z, but you can use a trick like this:

qpdf --empty --pages $(for i in a*.pdf; do echo $i 1-z; done) -- b.pdf

The syntax above would work with bash or any Bourne-shell or Korn-shell compatible shell. Will that meet your needs?

@rbro
Copy link
Author

rbro commented Jun 2, 2013

Yes, that's a neat idea. I will use that for now. Would it be possible to add the ability to do it directly in the future? I find myself often needing to combine entire pdf files on the command line. Thanks.

@qpdf
Copy link
Collaborator

qpdf commented Jun 2, 2013

I'll put it on the to-do list. It should be doable without creating any significant ambiguity. Thanks for the suggestion.

@qpdf
Copy link
Collaborator

qpdf commented Jun 2, 2013

I'll leave the issue open and will resolve it if/when I add this to a future version.

@qpdf
Copy link
Collaborator

qpdf commented Jun 15, 2013

This issue is targeted for 4.2.0 which I hope to get out within the week.

@qpdf
Copy link
Collaborator

qpdf commented Jul 7, 2013

I have implemented this change. I'm closing this issue. 4.2.0 is ready to go, a little later than I hoped.

@qpdf qpdf closed this as completed Jul 7, 2013
@lukeenglish
Copy link

Hi, can you post the syntax to do this so myself and others visiting this issue from google know how to do this as of 4.2.0?

@jberkenbilt
Copy link
Contributor

You can now do

qpdf --empty --pages *.pdf -- out.pdf

@lukeenglish
Copy link

Thanks Jay

@X1z1
Copy link

X1z1 commented Jul 15, 2016

In qpdf 6.0.0, if i use
qpdf --empty --pages *.pdf -- out.pdf
i get "open *.pdf: Invalid argument".

So every time I need to specify the name of files (like "qpdf --empty --pages a1.pdf a2.pdf -- out.pdf").
Why "qpdf --empty --pages *.pdf -- out.pdf" don't work?

@jberkenbilt
Copy link
Contributor

What operating system or shell are you using? This will only work on a UNIX/Linux like system that does wildcard expansion in the shell. If you are using this on Windows, it will not work.

@X1z1
Copy link

X1z1 commented Jul 20, 2016

I use Windows.
There is a command (or batch script) in Windows that automatically merge all pdfs in a folder.

@Kittukahier
Copy link

Kittukahier commented Dec 7, 2016

Hello X1z1, I also use Windows, and I have Cygwin installed in Windows, somehow it emulates a UNIX/Linux like system, it gives you a shell or terminal to work with.
So I've installed "qpdf", I've got two documents, doc01.pdf (4 pages) and doc02.pdf (1 page). I needed to merge doc02.pdf as page # 4, so I did like this:

qpdf doc01.pdf --pages doc01.pdf 1-3 doc02.pdf 1 doc01.pdf 4 -- out.pdf

And it worked perfectly.

@CMCDragonkai
Copy link

CMCDragonkai commented Jun 19, 2017

Is there an opposite syntax for splitting? That is split all pages of a pdf into separate files while the filenames are enumerated from a template?

Because right now I am manually figuring out the number of pages, and then running a page extraction for each page.

@jberkenbilt
Copy link
Contributor

@CMCDragonkai See #30 and #110. I think I'm going to add something soon.

@alexhunsley
Copy link

Any word on how to do this when there are spaces in the PDF filenames?
if there are spaces, even escaped ones ('\ '), qpdf cannot handle them.

@jberkenbilt
Copy link
Contributor

qpdf doesn't care what the file names are. If you are having a problem with spaces in file names, it's probably a shell escaping problem. If you are having too much trouble getting your shell to escape things properly, you can put each argument, one argument per line, in a file and use @file syntax as explained in qpdf --help.

@devurandom
Copy link

devurandom commented Oct 4, 2018

I don't seem to understand the syntax: I try to use qpdf --pages primary-document.pdf {other,documents}.pdf -- out.pdf (the {x,y} is expanded by my shell) and get this error message: qpdf: an output file name is required; use - for standard output. There are no spaces in the filenames. Version is 8.2.1.

@jberkenbilt
Copy link
Contributor

@devurandom You need an input file. It's treating out.pdf as the input file. If you don't have an input file, you can use --empty. Try qpdf --empty --pages primary-document.pdf {other,documents}.pdf -- out.pdf.

@jberkenbilt
Copy link
Contributor

Alternatively, you can repeat primary-document.pdf for qpdf primary-document.pdf --pages primary-document.pdf {other,documents}.pdf -- out.pdf. The difference here is that document-level structure such as outlines, page numbers, etc., will be copied from the primary document.

@GreenRaccoon23
Copy link

Windows/PowerShell users also need to put quotes around the -- argument.

For example, running this:

qpdf --empty --pages input.pdf -- output.pdf

Results in this error:

qpdf: error at * in numeric range *output.pdf: unexpected character

The correct syntax for PowerShell is this:

qpdf --empty --pages input.pdf '--' output.pdf

@tarifa10
Copy link

tarifa10 commented Aug 2, 2020

hello dear all

i just run into terrible issues: see here for more deatails: https://www.linuxquestions.org/questions/showthread.php?p=6151676#post6151676


martin@mx:~/Dokumente/kalender/ueberschaar__fixes_urlaub
$ qpdf 98_225.pdf --pages . 1-z:even -- odd.pdf

qpdf: error at * in numeric range 1-z*:even: unexpected character

Usage: qpdf [options] infile outfile
For detailed help, run qpdf --help

martin@mx:~/Dokumente/kalender/ueberschaar__fixes_urlaub
$ 
martin@mx:~/Dokumente/kalender/ueberschaar__fixes_urlaub
$ qpdf 98_225.pdf --pages 98_225.pdf 1-z:odd -- even.pdf

qpdf: error at * in numeric range 1-z*:odd: unexpected character

Usage: qpdf [options] infile outfile
For detailed help, run qpdf --help

now i finally encountered that there something is totally wrong with my system: i cannot copy and paste commands - this does not work here. so i finally do one thing: i will type all the commands character by character...

question: should i type each of the four lines - i guess so. i guess that i need all the four lines.

look forward to hear from you - either here or there https://www.linuxquestions.org/questions/showthread.php?p=6151676#post6151676

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

11 participants