A quick reference guide covering PDF techniques and repeatable workflows.
PDF Compression & Optimization
Reduce PDF file size through compression, flattening, rasterization, and structural optimization.
Balanced Compression
Compress a PDF while preserving the original color space and maintaining good image quality.
\gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.7 \ -dPDFSETTINGS=/ebook \ -dColorConversionStrategy=/LeaveColorUnchanged \ -dDownsampleColorImages=true \ -dColorImageResolution=150 \ -dNOPAUSE -dQUIET -dBATCH \ -sOutputFile=compressed-balanced.pdf input.pdfMaximum Compression
Reduce PDF file size as much as possible, prioritizing smaller files over image quality.
\gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 \ -dPDFSETTINGS=/screen \ -dNOPAUSE -dBATCH \ -sOutputFile=compressed.pdf input.pdfVector Flattening
Flatten PDF content while retaining vector graphics and the original color space.
\gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 \ -dPDFSETTINGS=/ebook \ -dColorConversionStrategy=/LeaveColorUnchanged \ -dPreserveAnnots=false \ -dPreserveFlattenedNC=false \ -dNOINTERACTION -dNOPAUSE -dQUIET -dBATCH \ -sOutputFile=flattened-vector.pdf input.pdfAnnotation Flattening
Flatten annotations and page rotation into the PDF content.
qpdf --flatten-annotations=all --flatten-rotation input.pdf flattened-annotations.pdfStructural Optimization
Linearize the PDF and optimize embedded images and unreferenced objects.
qpdf --linearize --optimize-images input.pdf optimized-structural.pdfImage Optimization with Quality
Recompress images with a specified JPEG quality when optimization reduces file size.
qpdf --optimize-images --jpeg-quality=85 input.pdf optimized-images-quality.pdfPDF Page Size & Scaling
Resize PDF pages to standard paper sizes while preserving the page content and aspect ratio.
Resize to Paper Size
Resize PDF pages to a fixed paper size while scaling and centering the original content to fit.
\gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 \ -sPAPERSIZE=letter \ -dFIXEDMEDIA \ -dPDFFitPage \ -dAutoRotatePages=/None \ -dModifiesPageSize=true \ -dNOPAUSE -dBATCH -dQUIET \ -sOutputFile=resized-letter.pdf input.pdfResize to Exact Dimensions
Resize PDF pages to exact dimensions in points while scaling and centering the original content to fit.
\gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 \ -dDEVICEWIDTHPOINTS=612 \ -dDEVICEHEIGHTPOINTS=792 \ -dFIXEDMEDIA \ -dPDFFitPage \ -dAutoRotatePages=/None \ -dModifiesPageSize=true \ -dNOPAUSE -dBATCH -dQUIET \ -sOutputFile=resized-letter-exact.pdf input.pdfpdfinfo -f 1 -l $(pdfinfo "resized-letter-exact.pdf" | awk '/Pages/ {print $2}') "resized-letter-exact.pdf" | grep -E "Page.*size:"