How-to pdf
Convert from/to pdf
Convert a pdf into a djvu file (about 10% of the pdf size)
pdf2djvu -o output_file input_file
Convert a pdf into a png file (single page)
pdftoppm input_file.pdf output_file -png -f 1 -singlefile -rx 300 -ry 300
(here page number is “1”, dpi quality is “300”)
Convert a djvu file into a pdf file
djvups doc.djvu doc.ps
ps2pdf doc.ps
Convert all eps files in a directory into pdf files
find . -name "*.eps" -exec epstopdf {} \;
Convert a jpg file into a pdf file
convert -compress jpeg -quality 85 p*.jpg out.pdf
pdf2ps out.pdf out.ps
ps2pdf f.ps
Convert an epub file into a pdf file
ebook-convert foo.epub foo.pdf
With more options for a better output:
ebook-convert foo.epub foo.pdf --margin-bottom "75" --margin-top "75" --margin-left "75" --margin-right "75" --pdf-serif-family "Calibri" --pdf-sans-family "Calibri" --base-font-size "14" --pdf-mono-font-size "12" --paper-size "a4" --change-justification "justify"
In Mac OS:
brew cask install calibre
export PATH=/Applications/calibre.app/Contents/MacOS/:$PATH
ebook-convert book.epub book.pdf --margin-bottom "75" --margin-top "75" --margin-left "50" --margin-right "50" --pdf-serif-family "Calibri" --pdf-sans-family "Calibri" --base-font-size "12" --pdf-mono-font-size "12" --paper-size "a4" --change-justification "justify"
Convert a svg file into a pdf file
Method that works well (not necessary in MacOS)
rsvg-convert -f pdf -o t.pdf t.svg
Method that works less well
cairosvg image.svg -o image.pdf
Idem (in python3)
import cairosvg
cairosvg.svg2pdf(url='image.svg', write_to='image.pdf')
Manipulate a pdf file
Concatenate several pdf files
pdftk 1.pdf 2.pdf 3.pdf cat output 123.pdf
Rotate by 180 degrees pdf file
Single-page file (“1”)
pdftk in.pdf cat 1south output out.pdf
All pages (“1-end”)
pdftk in.pdf cat 1-endsouth output out.pdf
Extract pages from different pdf files (without removing them from the original files…)
pdftk A=f1.pdf B=f2.pdf cat A12-14 B2-34 A15 output outf.pdf
Extract one page from a djvu file
djvused landau4.djvu -e 'select 22; save-page out22.djvu'
Concatenate pages from different djvu files
djvm -c doc.djvu out18.djvu out19.djvu out20.djvu out21.djvu out22.djvu out23.djvu
Extract pieces of a pdf file
Extract an element from a pdf file (figure, anything)
Cuts by “290”, “140”, etc. points on the bottom, left, etc.
pdfcrop --margins '-290 -140 -290 -130' old.pdf new.pdf
Then remove “hidden stuffs” around the extracted piece that pdfcrop did not remove:
pdf2ps out.pdf out.ps
ps2pdf f.ps
Or better:
pdfcrop --margins 0 old.pdf new.pdf
Reduce the size of a pdf
convert -density 300x300 -quality 2 -compress jpeg input.pdf out.pdf