Skip to content

Here are some helpful things I've found

Shrink PDF

https://askubuntu.com/a/256449

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf
  • dPDFSETTINGS=/screen lower quality, smaller size. (72 dpi)
  • dPDFSETTINGS=/ebook for better quality, but slightly larger pdfs. (150 dpi)
  • dPDFSETTINGS=/prepress output similar to Acrobat Distiller “Prepress Optimized” setting (300 dpi)
  • dPDFSETTINGS=/printer selects output similar to the Acrobat Distiller “Print Optimized” setting (300 dpi)
  • dPDFSETTINGS=/default selects output intended to be useful across a wide variety of uses, possibly at the expense of a larger output file

Split PDF by chapter

A script has been written in login git repository named pdf_split.bookmark.pl

pdf_split_bookmark.pl big.pdf

Batch convert PDF to jpg

https://askubuntu.com/questions/1162790/batch-convert-an-entire-folder-of-pdf-files-to-jpg-or-png-using-pdftoppm-in-ubun

find . -maxdepth 1 -type f -name '*.pdf' -exec pdftoppm -jpeg {} {} \;

For single convert

pdftoppm -jpeg example.pdf example

JPEG to PDF

convert *.jpg pictures.pdf

Merge PDF pages

pdftk A=source.pdf B=merged.pdf cat A1-45 B A46-end output final.pdf

Split PDF pages

pdftk A=source.pdf cat A22-24 output final.pdf

Remove password from pdf

pdftk input.pdf input_pw PROMPT output output.pdf

Perl pie

perl -pi -e 's/foo/bar/g;' `find . -name '*.html' -type f`

Search and Replace

grep -rl matchstring somedir/ | xargs sed -i 's/string1/string2/g'

Animated GIF

https://www.ostechnix.com/create-animated-gif-ubuntu-16-04/

ffmpeg -ss 00:00:20 -i sample.mp4 -to 10 -r 10 -vf scale=200:-1 cutekid_cry.gif
  • ss : indicates the starting point of GIF
  • i : input file : sample.mp4 : My video file name
  • to : End position of the GIF file
  • r : frame rate. You can increase the value to get more quality GIF file
  • vf : filter graph. To scale the GIF image in the desired size.

Create Encrypted Zip File

https://itsfoss.com/password-protect-zip-file/

The -e option encrypts

zip -re output_file.zip file1 folder1

xargs piping

When piping to xargs, I always forget what the syntax is to ignore whitespaces.

find . -name '*.jpg' | xargs -d '\n' rm

Synergy stuck ctrl key

https://github.com/debauchee/barrier/issues/207

If the ctrl key gets stuck within the synergy client, you can fix this with this command

#!/usr/bin/env bash

setxkbmap -layout us
xdotool keyup Shift_L Shift_R Control_L Control_R Alt_L Alt_R Super_L Super_R Hyper_L Hyper_R Caps_Lock 204 205 206 207

Convert image files to webp

We need to install the webp or libwebp or libwepb-tools package depending on your OS.

Then

cwebp image.png -o image.webp

You can set the quality with the -q option.

If you have a lot of PNG photos to convert, you can use a Bash for loop to bulk convert hundreds or thousands of PNG photos to WebP at once.

for f in *.png; do cwebp -q 85 -mt $f -o ${f%.*}.webp; done

If you have PNG files scattered throughout subdirectories, you can use the find command to traverse subdirectories and convert every .PNG (or .png) file that it finds.

find . -iname "*.png" -exec sh -c 'cwebp -q 85 -mt "$1" -o "${1%.*}.webp"' sh {} \;