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) ).
Use PDF tools from python https://pypi.python.org/pypi/pdftools/1.0.6
Download the tar.gz file and uncompress it and run the command like below
You should install pyhton3 before you run the above command
This tools support the below
You can find more details in the below link and it is open source
https://github.com/MrLeeh/pdftools
Here's a method I use which works and is easy to implement. This will require both the fpdf and fpdi libraries which can be downloaded here:
I second the
pdfunite
recommendation. I was however gettingArgument list too long
errors as I was attempting to merge > 2k PDF files.I turned to Python for this and two external packages: PyPDF2 (to handle all things PDF related) and natsort (to do a "natural" sort of the directory's file names). In case this can help someone:
pdfunite
is fine to merge entire PDFs. If you want, for example, pages 2-7 from file1.pdf and pages 1,3,4 from file2.pdf, you have to usepdfseparate
to split the files into separate PDFs for each page to give topdfunite
.At that point you probably want a program with more options.
qpdf
is the best utility I've found for manipulating PDFs.pdftk
is bigger and slower and Red Hat/Fedora don't package it because of its dependency on gcj. Other PDF utilities have Mono or Python dependencies. I foundqpdf
produced a much smaller output file than usingpdfseparate
andpdfunite
to assemble pages into a 30-page output PDF, 970kB vs. 1,6450 kB. Because it offers many more options,qpdf
's command line is not as simple; the original request to merge file1 and file2 can be performed withAfter searching many of the available pdf libraries, the only thing which worked perfectly for me is
https://libraries.io/npm/easy-pdf-merge
It requires Java 6 or above to be installed but works perfectly. Pdftk is full of bugs.
If you want to convert all the downloaded images into one pdf then execute
convert img{0..19}.jpg slides.pdf