Go Job Hunting at the LQ Job Marketplace
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 10-06-2004, 04:26 AM   #1
Senior Member
Registered: Oct 2001
Location: Bristol UK
Distribution: Slackware Ubuntu
Posts: 1,044

Rep: Reputation: 42
merge multiple pdf files

I have about 30 pdf files that I want as 1 pdf file. The command cat seems to be the answer to my problems - cat 1.pdf 2.pdf > new.pdf . I do not want to type the names of all the pdf files into this command (most of the file names are are long) so I hoped that cat *.pdf > new.pdf would give me what I need. It doesn't. new.pdf is created but it only contains the contents of the file 1.pdf --- none of the others. What am I missing? This is the first time I've used cat.
Thanks - I hope that I'm not missing something *too* obvious.
Old 10-06-2004, 06:28 AM   #2
Registered: Aug 2004
Location: Germany
Distribution: Slackware 10.0
Posts: 258

Rep: Reputation: 30
I am not sure if your idea will be working ... never tried it out.

But you could have a look into CPAN ... there is at least one perl-module, that should fit your needs; and it isn't hard to use. I did something similar in one of my first perl-scripts ...

Greetings, Sascha
Old 10-06-2004, 07:06 AM   #3
Registered: May 2003
Location: London
Distribution: kubuntu 8.10
Posts: 593
Blog Entries: 1

Rep: Reputation: 30
I don't know the pdf format but the cat > technique implies that the files are not structured with headers, like a start and end of documents.

If the pdf docs are structured like that, then compiling them won't make them a valid pdf.
Old 10-06-2004, 07:59 AM   #4
Senior Member
Registered: Apr 2001
Location: Plymouth, England.
Distribution: Debian + Ubuntu
Posts: 4,358

Rep: Reputation: 57
Ok, very simple here:

If the PDF document format supports this method of joining files (which I doubt) then the problem is in the use of >.

What you're doing is this:
cat file1.pdf > new.pdf
Create a new file called new.pdf containing the contents of file1.pdf.
cat file2.pdf > new.pdf
Create a new file, or overwrite existing file, called new.pdf containing the contents of file2.pdf.

You see the problem? Now, if you were to you >> (double chevron) then file2.pdf would be appended to new.pdf.

If you have lots of files you could do this (presuming they're all in one directory):
for name in *.pdf (enter)
do (enter)
cat $name.pdf >> new.pdf (enter)
done (enter)

Obviously, if you want finer control, you can change the above as such:

for name in 1 3 5 7 9
cat file$name.pdf > new.pdf

Hope this helps.
If this doesn't work because PDF doesn't support this method of concatenating, then you could:

Convert each PDF document into a series of image files.
Convert all the image files into a single PDF file.

This will probably be a touch more time consuming.

Last edited by Thymox; 10-06-2004 at 08:01 AM.
Old 10-06-2004, 08:45 AM   #5
LQ Newbie
Registered: Oct 2003
Location: Austin, Texas
Distribution: Ubuntu
Posts: 6

Rep: Reputation: 0
In that case ... the last pdf file should be there in the new.pdf file, right? But he said that the first pdf file is only there. So maybe some other reason is there
Old 10-06-2004, 09:00 AM   #6
Senior Member
Registered: Oct 2001
Location: Bristol UK
Distribution: Slackware Ubuntu
Posts: 1,044

Original Poster
Rep: Reputation: 42
well. thanks for your replies. It seems that cat does not work for pdf files. I was barking up the wrong tree
Old 10-22-2004, 10:27 PM   #7
Registered: Aug 2003
Location: Chicago, USA
Distribution: RHEL, CentOS, Ubuntu
Posts: 43

Rep: Reputation: 15
I used this in the past to merge pdf's. It worked really nice in Red Hat 9.0:

texexec --pdfarrange --result newfile.pdf first_doc_to_merge.pdf second_doc.pdf third_doc.pdf

I think I did 10 files but it should work with any number. In order to make this work you have to type in "texconfig formats" and uncomment the line


I just checked in FC2 and it was already uncommented. The files you merge have to end in .pdf in order to work. The order you put the pdf's in is the order they will be merged in. I have not tried this on anything but red hat 9.0. Maybe someone else can help with a script. Good luck.
Old 02-08-2006, 04:43 PM   #8
LQ Newbie
Registered: Jan 2006
Posts: 15

Rep: Reputation: 0
You can install PDF editor in Wine (I managed it in Fedora)

Though I havent tried addign pages but I think you might succeed in merging files

good luck
Old 11-21-2007, 01:59 PM   #9
Senior Member
Registered: Jun 2007
Location: E.U., Mountains :-)
Distribution: Debian, Etch, the greatest
Posts: 2,546

Rep: Reputation: 57
The first method is by using convert , directly from the ImageMagick toolkit. You probably already have this one installed on your favourite Linux distribution; if not, almost every known Linux distribution has a package for it. Even if you don't need to edit PDF files you should have it, it is a wonderful swiss army knife for command line image processing. The syntax for merging PDF files is simple:

convert file1.pdf file2.pdf file3.pdf out.pdf

(that is, the last file name is the output file name). This usually works quite correctly, but 1)it is slow 2)I found sometimes has issues with image resolution. So I looked for another solution, and I found pdftk. The name stands for "PDF ToolKit", and really it is. It is a free (open source under the GNU GPL), wonderful command line utility that with a bit of magic allows you to manage PDF files from the command line. It works on Linux, Windows and Mac. pdftk can merge PDF documents, split PDF pages into a new document, rotate PDF Pages or Documents, decrypt and encrypt, fill PDF forms, apply a background watermark or a foreground stamp, burst a PDF Document into single pages... whatever.

The syntax for merging with pdftk is almost as simple:

pdftk file1.pdf file2.pdf file3.pdf cat output out.pdf

You just need to add the magic "cat output" between the input pdfs and the output file name. In comparison with convert, it is truly fast and in my experience gives better results. And it may come handy for when I have to work with PDF files in other ways. Also, KDE users may find nice PDF Concat, a Kommander script that acts as a simple pdftk frontend to merge PDFs.

texexec --pdfarrange --result newfile.pdf *.pdf

Last edited by frenchn00b; 11-21-2007 at 02:02 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Merge Of Html Files Into A Single Html (or Pdf) fiomba Linux - Software 6 06-20-2011 07:28 PM
How To Merge multiple files into a single PDF ? kkempter Linux - Software 1 10-28-2005 01:02 PM
printing from multiple pdf files the first page harmster Linux - Software 2 05-09-2005 07:06 AM
merge multiple lines of a single file into one line groverrajiv Linux - Newbie 4 05-26-2004 02:38 AM
[AVI, mencoder, merge files] MrGreg Linux - Software 5 01-02-2003 05:46 AM

All times are GMT -5. The time now is 03:30 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration