Shrink PDF and make text searchable and copy-able with OCRmyPDF and Ghostscript

Create a copy of a PDF with searchable and copy-able text with OCRmyPDF. Specify language with for example -l dan. --sidecar outputs the text in a separate text file.

ocrmypdf inputpdf.pdf output.pdf --sidecar

Compress PDF with Ghostscript.

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

A PDF can get reduced from 14 MB to 2 MB with this method, with hardly any loss of quality. -dPDFSETTINGS=/ebook adjusts output quality.