# A terminal tool for PDF?



## kalleboy (Jan 21, 2022)

Is there any terminal tool to merge two PDF files (or more) into a single one?


----------



## covacat (Jan 21, 2022)

ghostscript, maybe others


----------



## bsduck (Jan 21, 2022)

I use print/pdftk.


----------



## T-Daemon (Jan 21, 2022)

graphics/poppler-utils comes with pdfunite. You may have the package already installed as a dependency.


----------



## vermaden (Jan 21, 2022)

kalleboy said:


> Is there any terminal tool to merge two PDF files (or more) into a single one?


Install the print/pdftk.package:

```
# pkg install pdftk
```

Then download this:
https://github.com/vermaden/scripts/blob/master/pdf-concat.sh

Usage:

```
% pdf-concat.sh FILE1.pdf FILE2.pdf *.pdf
```

You will get ALL.pdf file with all PDF file concatenated.

Other PDF scripts from my page:

- pdf-decrypt.sh
- pdf-extract.sh
- pdf-rotate-left.sh
- pdf-rotate-right.sh
- pdf-split.sh


Regards.


----------



## scottro (Jan 21, 2022)

I also use pdftdk.   Very simple to use. I see vermaden offers a script (and several other typically useful ones) but even without, it's just 

```
pdftk file1.pdf file2.pdf cat output newfile.pdf
```


----------



## covacat (Jan 21, 2022)

the "terminal" tool for pdf (or any other file type ) is rm


----------



## JohnnySorocil (Jan 21, 2022)

I am using `qpdf`.

```
pkg info qpdf | grep Comment
Comment        : Command-line tools for transforming and inspecting PDF documents
```

I am usually using it to separate pages to new pdf:

```
qpdf input.pdf --pages . 1-10 -- output.pdf
```
It can be used for merging pages also, but I don't have example right now.


----------



## vermaden (Jan 21, 2022)

scottro said:


> ```
> pdftk file1.pdf file2.pdf cat output newfile.pdf
> ```


I always messed up the order of cat/output syntax so that is the reason why I created these 'wrappers'


----------



## scottro (Jan 21, 2022)

Well, your loss helps all the people who make use of your scripts, so there's the bright side. 
To be honest, I usually have to websearch the syntax the few times I have to make use of it.


----------



## ruaoh (Jan 22, 2022)

I use ghostscript.  Even on Windows (gswin32.exe) since all of the PDF printers I've come across use ghostscript.
`gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=outfile.pdf infile1.pdf infile2.pdf`


----------



## SKull (Jan 27, 2022)

Printers use Postscript.
Ghostscript generates Postscript.
But not if you use pdfwrite 

But your solution certainly works here.

Nothing wrong with ghostscript. It's super useful albeit slow if you work with lots of PDFs and pages.


----------



## richardtoohey2 (Jan 27, 2022)

qpdf is probably the lightest in terms of install/dependancies.  I think the other solutions are a LOT heavier just for merging.


----------



## bakul (Jan 27, 2022)

With pdfcpu you should be able to do all sorts of useful things with pdf files. You will need Go.
`git clone https://github.com/pdfcpu/pdfcpu
cd pdfcpu/cmd/pdfcpu
go install

pdfcpu help
pdfcpu help merge
pdfcpu merge out.pdf in1.pdf in2.pdf ...`


----------



## CanvisMe (Jan 27, 2022)

Though I didn't use the edit function of graphics/mupdf, which provides `mutool` to manipulate pdf files, you can try it. It's light and fast.


----------



## sko (Jan 27, 2022)

The convert(1) tool from graphics/ImageMagick7 can also be used to mangle pdf files.
Apart from concatenating multiple files it can also convert from various formats into pdf and shrink/resize/compress, add watermarks or backgrounds, rotate, crop or filter images etc. pp... It may be total overkill for your task, but as ImageMagick is a dependency of several other programs, chances are that it's already installed anyways.


----------

