PDF management


Merge PDF files:

gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=finished.pdf file1.pdf file2.pdf

Split PDF file:

gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -dFirstPage=m -dLastPage=n -sOutputFile=out.pdf in.pdf


  • Split and merge PDF files:
    pdftk 1.pdf 2.pdf 3.pdf cat output 123.pdf
    pdftk A=one.pdf B=two.pdf cat A1-7 B1-5 A8 output combined.pdf
    pdftk A=one.pdf B=two.pdf cat A1 B1W output combined.pdf # rotate West B1 (E,N,W,S)
    pdftk one.pdf two.pdf shuffle output combined.pdf # shuffle the two files (A1 B1 A2 B2 A3 B3...)
  • Encrypt/decrypt, set permissions, repair:



  • split and merge:
    pdfjam file1.pdf '-' file2.pdf '1,2' file3.pdf '2-' --outfile output.pdf
  • set multiple pages in one:
    pdfjam --nup 2x1 --landscape true --frame false file.pdf
  • quickly rotate (pdf90, pdf180, pdf270):
    pdf90 file1.pdf


  • crop pages (here remove 14% of page height at the bottom):
    sed 's/MediaBox \[0 0 612 1008*/MediaBox \[0 145 612 1008]/g'<in.pdf >out.pdf

    /!\ some tools such as pdftk or gs may consider the file as corrupted afterwards

convert (image magick)

Merge image files into a pdf file:

convert page-*.png -page A4 [-rotate 90] test.pdf
convert -density 300x300 test.png test.pdf
convert -units PixelsPerInch -density 300x300 -extent 2480x3508 -gravity center -background white test.png test.pdf

Convert pdf page into image file at resolution 300dpi:

convert -density 300x300 test.pdf test.png


To grep into a pdf file:

pdftotext file.pdf - | grep "text"


To add text on a pdf file. You can save the file, but it doesn't work with landscape oriented pages…


To add text, drawings, and highlight a pdf file. More complete and less buggy than flpsed.

PDF-XChange Viewer

Can deal with real PDF annotations (yellow boxes).

Software for Windows, but that works in Wine (download the exe installer).

software/pdf.txt · Last modified: 2014/10/20 08:41 by cyril
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki