Install Ghostscript: If it’s not already installed, you can install Ghostscript using your distribution’s package manager. For Debian-based systems like Ubuntu, use:
sudo apt-get update sudo apt-get install ghostscriptFor Red Hat-based systems like Fedora, use:
sudo dnf install ghostscriptCompress the PDF: Once Ghostscript is installed, you can compress your PDF file using the following command:
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdfIn this command:
input.pdfis the name of your original PDF file.output.pdfis the name of the compressed PDF file that will be created.-dPDFSETTINGS=/screensets the quality of the PDF. This setting is for the lowest quality and smallest file size, which is suitable for viewing on a screen. Other options include/ebookfor medium quality,/printerfor high quality, and/prepressfor high quality with large file size.
To reduce the compression level in Ghostscript when converting or processing a PDF file, you can adjust the -dPDFSETTINGS option. The command you provided is set to use the /screen setting, which applies high compression and low-resolution output, suitable for viewing on a screen but not ideal for printing or archiving.
The available settings for -dPDFSETTINGS are:
/screen– lowest quality, highest compression./ebook– better quality, but still a fair amount of compression./printer– high quality, suitable for printing documents./prepress– high quality, similar to/printerbut with a higher resolution, suitable for printing to a prepress standard./default– a useful starting point, balancing quality and compression.
To reduce the compression level (i.e., to increase the quality of the output PDF), you can switch from /screen to a higher quality setting like /ebook, /printer, or /prepress. For example, if you want a balance between quality and file size, you might choose /ebook:
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=patient-record-oldbury-health-centre-1.pdf patient-record-oldbury-health-centre.pdfOr, for higher quality suitable for printing, use /printer:
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/printer -dNOPAUSE -dQUIET -dBATCH -sOutputFile=patient-record-oldbury-health-centre-1.pdf patient-record-oldbury-health-centre.pdf