Merge / convert multiple PDF files into one PDF

2019-01-02 16:19发布

How could I merge / convert multiple PDF files into one large PDF file?

I tried the following, but the content of the target file was not as expected:

convert file1.pdf file2.pdf merged.pdf

I need a very simple/basic command line (CLI) solution. Best would be if I could pipe the output of the merge / convert straight into pdf2ps ( as originally attempted in my previously asked question here: Linux piping ( convert -> pdf2ps -> lp) ).

17条回答
余生无你
2楼-- · 2019-01-02 17:04

The other answers are good, but if you cannot merge PDFs locally, whether you are in a shared hosting environment, or for other reasons, they will not help you.

If you are looking for an API to merge PDFs remotely, you can try api2pdf which has an endpoint for merging pdfs together. Documentation is here.

查看更多
春风洒进眼中
3楼-- · 2019-01-02 17:05

I'm sorry, I managed to find the answer myself using google and a bit of luck : )

For those interested;

I installed the pdftk (pdf toolkit) on our debian server, and using the following command I achieved desired output:

pdftk file1.pdf file2.pdf cat output output.pdf

OR

gs -q -sPAPERSIZE=letter -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=output.pdf file1.pdf file2.pdf file3.pdf ...

This in turn can be piped directly into pdf2ps.

查看更多
几人难应
4楼-- · 2019-01-02 17:05

This is the easiest solution if you have multiple files and do not want to type in the names one by one:

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

查看更多
宁负流年不负卿
5楼-- · 2019-01-02 17:06

Considering that pdfunite is part of poppler it has a higher chance to be installed, usage is also simpler than pdftk:

pdfunite in-1.pdf in-2.pdf in-n.pdf out.pdf
查看更多
忆尘夕之涩
6楼-- · 2019-01-02 17:06

Also pdfjoin a.pdf b.pdf will create a new b-joined.pdf with the contents of a.pdf and b.pdf

查看更多
登录 后发表回答