Tuesday, February 13, 2007

Combining multiple PDF files in one

http://www.debianadmin.com/combine-multiple-pdfs-into-one-file-in-ubuntu-linux.html
http://www.newsforge.com/article.pl?sid=04/06/09/1844259

Preparing Your system
sudo apt-get install gs pdftk
(Merge, merging, cancatenate, concatenating pdf files)

Now we will see one example how to combine pdf files let us assume we have 1.pdf,2.pdf,3.pdf files and now we need to cobmine this files using the following command:
gs -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=combinedpdf.pdf -dBATCH 1.pdf 2.pdf 3.pdf
Another different approach:
gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=finished.pdf file1.pdf file2.pdf
In the above command after “-sOUTPUTFILE=” type whatever name you want for the merged file (don’t forget to append .pdf to the end of the file name). Rename “1.pdf 2.pdf 3.pdf” to whatever your file names are (separate your file names with a space).
After you run the above command, a new PDF file called combinedpdf.pdf will be created with your individual files merged according to the order you list.
The same can be done with PS files:
gs -sDEVICE=pswrite -sOutputFile=output.ps -dNOPAUSE -dBATCH file1.ps file2.ps file3.ps
If you want to know more options available for gs command check man page

Tags: , , , , , , ,

Merge PDF files with pdftk
Having some of my manuals/documentations downloaded in several separated pdf files, I wanted to merge them into a single file.

First, I installed pdftk

# apt-get install pdftk

In Ubuntu 18.04 the previous command won't work. Instead:

sudo snap install pdftk

Then, I merged the files into a single file

$ pdftk   file1.pdf    file2.pdf    file3.pdf   cat  output   file123.pdf

When the files to be merged is a lot, I edited the file list in a text editor (or, when I am in a good mood, using ls & awk & sed) then combine it with the script found here

$ cat stdin_pdf.sh
#!/bin/sh
# combine PDFs; pass filenames in on stdin;
# pass output to stdout
read input_filenames
pdftk $input_filenames cat output -

$ cat filelist|./stdin_pdf.sh>mergedfile.pdf

So far, I am satisfied with the result. (link)