Wei Zhang's Blog

30 Sep 2021

Some useful commands under Ubuntu

In this post we record several useful commands/softwares under Ubuntu.

  • convert is a very powerful command for post-processing images. For example, the following command is used to reduce the size of a jpg file.

    	convert -resize 30% input.jpg output.jpg
    
  • pdftk can be used to process pdf files. Below are two examples.

    1. To merge 1.pdf and 2.pdf files into one pdf file named 1-and-2.pdf, use
    	pdftk 1.pdf 2.pdf cat output 1-and-2.pdf
    
    1. Extract the first, the third and the fourth pages of the file input.pdf to output file out.pdf
    	pdftk input.pdf cat 1 3-4 output out.pdf
    
  • pdftoppm can convert a pdf file to JPEG format. Suppose the input pdf file contains two pages, then the command

      pdftoppm -jpeg -r 300 input.pdf output
    

    will produce two JPEG files, named as output-1.jpg and output-2.jpg. In the above, ‘'-r 300’' specifies the resolution of the output pictures.

  • The following command uses gs to reduce the size of a pdf file.

    	gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf
    

    More details can be found here.

  • img2pdf converts a JPEG file to PDF format. As an example,

      img2pdf --pagesize A4 input.jpg -o output.pdf