Обработка pdf файлов
pdftk
Extract the 5th page from the source.pdf and save it to the result.pdf:
pdftk source.pdf cat 5 output result.pdf
or range
pdftk source.pdf cat 1 4 6 output result.pdf
pdftk source.pdf cat 1-5 output result.pdf
pdftk source.pdf cat 1 5 7 10-12 output result.pdf
imagemagick
sudo apt-get install imagemagick
convert *.jpg pictures.pdf
convert `ls -1v` file.pdf
convert page1.jpg page2.jpg +compress file.pdf
convert -rotate 90 page\*.jpg +compress file.pdf
convert FILE1.pdf FILE2.pdf OUTPUT.pdf
convert FILE1.pdf[1] FILE2.pdf[0,5] FILE3.pdf[0,5] OUTPUT.pdf
*You need a special -density flag with dpi value corresponding to the original file quality, because the default value is about 90: convert FILE1.pdf FILE2.pdf -density 200 OUTPUT.pdf
or convert -density 200 FILE1.pdf FILE2.pdf OUTPUT.pdf
pdfunite to merge files
pdfunite 1.pdf 2.pdf 3.pdf 4.pdf out.pdf
pdfunite *.pdf result.pdf
pdfseparate to split files
pdfseparate source.pdf out-%d.pdf
Первые 3 страницы, с именами в стиле 0001.pdf с 1 по 3 страницу:
pdfseparate -l 3 source.pdf %04d.pdf
Первые 3 страницы, с именами в шаблоне out{n}.pdf с 3 до конца:
pdfseparate -f 3 -l 4 source.pdf out%d.pdf
Только 3,4 страницы :
pdfseparate -f 3 -l 4 source.pdf out%d.pdf
Только 3 страница :
pdfseparate -f 3 -l 3 source.pdf out%d.pdf
pdfimages 2 split pdf
sh pdf2jpg.sh file.pdf
pdf2jpg.sh:
#!/bin/bash
mkdir "${1%.*}"
echo 'how to use: sh pdf2jpg.sh file.pdf'
pdfimages -j "$1" ${1%.*}/${1%.*}
На выходе папка со страницами в виде картинок.
Compress PDF File In Linux
ps2pdf LARGE.pdf SMALL.pdf
To see result size input:
du -sh *.pdf
GhostScript examples.
https://www.ghostscript.com/doc/current/Use.htm
https://www.mankier.com/1/gs
http://linux-commands-examples.com/gs
http://www.nsc.ru/docs/ghost/Use.htm
To view a file:
gs -dQUIET -dBATCH file.pdf
See param as gs_param.sh:
gs \
-dDISPLAY \
-c ".distillersettings {exch ==only ( ) print ===} forall quit" \
Reduce PDF file size to 150 dpi images for reading on a ebook device:
gs -dNOPAUSE -dQUIET -dBATCH -sDEVICE=pdfwrite -dPDFSETTINGS=/ebook -sOutputFile=output.pdf input.pdf
Convert PDF file (pages 1 through 3) to an image with 150 dpi resolution:
gs -dQUIET -dBATCH -dNOPAUSE -sDEVICE=jpeg -r150 -dFirstPage=1 -dLastPage=3 -sOutputFile=output_%d.jpg input.pdf
Convert PDF to output{num}.jpg with 96 pdi resolution, using -o instead -sDEVICE:
gs -dQUIET -dBATCH -dNOPAUSE -sDEVICE=jpeg -r96 -o output_%d.jpg 1.pdf
Extract pages from a PDF file:
gs -dQUIET -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=output.pdf input.pdf
Merge PDF files:
gs -dQUIET -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=output.pdf input1.pdf input2.pdf
Convert from PostScript file to PDF file:
gs -dQUIET -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=output.pdf input.ps
Преобразовать в pdf 150dpi Grayscale:
gs -dQUIET -dBATCH -dNOPAUSE -r150 -sDEVICE=pdfwrite -sProcessColorModel=DeviceGray -sColorConversionStrategy=Gray -dOverrideICC -sOutputFile=output.pdf input.pdf
Походу эта зараза не умеет потоково давать на выходе имена файлам. Костыль поштучный, скриптом или так. Присвоим в баше алиас, добавить в конце фала /home/user/.bash_aliases строку:
alias pdf2gray="gs -dQUIET -dBATCH -dNOPAUSE -r150 -sDEVICE=pdfwrite -sProcessColorModel=DeviceGray -sColorConversionStrategy=Gray -dOverrideICC"
а далее
pdf2gray -sOutputFile='file(grey).pdf' 'file.pdf'