Skip to content
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

Syntax for merging entire PDF files #11

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

Comments

@rbro
Copy link

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.

@ghost

This comment has been minimized.

Copy link
Collaborator

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

This comment has been minimized.

Copy link
Author

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.

@ghost

This comment has been minimized.

Copy link
Collaborator

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.

@ghost

This comment has been minimized.

Copy link
Collaborator

commented Jun 2, 2013

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

@ghost

This comment has been minimized.

Copy link
Collaborator

commented Jun 15, 2013

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

@ghost

This comment has been minimized.

Copy link
Collaborator

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 Jul 7, 2013

@lukeenglish

This comment has been minimized.

Copy link

commented Jan 12, 2016

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

This comment has been minimized.

Copy link
Contributor

commented Jan 12, 2016

You can now do

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

@lukeenglish

This comment has been minimized.

Copy link

commented Jan 12, 2016

Thanks Jay

@X1z1

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link
Contributor

commented Jul 19, 2016

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link
Contributor

commented Jul 31, 2017

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

@alexhunsley

This comment has been minimized.

Copy link

commented Jan 10, 2018

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

This comment has been minimized.

Copy link
Contributor

commented Jan 10, 2018

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

This comment has been minimized.

Copy link

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

This comment has been minimized.

Copy link
Contributor

commented Oct 4, 2018

@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

This comment has been minimized.

Copy link
Contributor

commented Oct 4, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
9 participants
You can’t perform that action at this time.