LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   merge multiple pdf files (https://www.linuxquestions.org/questions/linux-software-2/merge-multiple-pdf-files-239328/)

esteeven 10-06-2004 04:26 AM

merge multiple pdf files
 
Hello
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.

theonebeyond 10-06-2004 06:28 AM

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

dukeinlondon 10-06-2004 07:06 AM

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.

Thymox 10-06-2004 07:59 AM

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
do
cat file$name.pdf > new.pdf
done


Hope this helps.
<edit>
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.
</edit>

sudipta_cht 10-06-2004 08:45 AM

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

esteeven 10-06-2004 09:00 AM

well. thanks for your replies. It seems that cat does not work for pdf files. I was barking up the wrong tree :)

dnorseman 10-22-2004 10:27 PM

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

cont-en

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.

ospreyeagle 02-08-2006 04:43 PM

You can install PDF editor in Wine (I managed it in Fedora)

http://forums.fedoraforum.org/showth...540#post450540

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

good luck

frenchn00b 11-21-2007 01:59 PM

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


All times are GMT -5. The time now is 04:54 AM.