Skip to content

pdf

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.

Terminal window
\gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.7 \
-dPDFSETTINGS=/ebook \
-dColorConversionStrategy=/LeaveColorUnchanged \
-dDownsampleColorImages=true \
-dColorImageResolution=150 \
-dNOPAUSE -dQUIET -dBATCH \
-sOutputFile=compressed-balanced.pdf input.pdf
-dColorImageResolution=(72 | 96 | 150 | 300)

Maximum Compression

Reduce PDF file size as much as possible, prioritizing smaller files over image quality.

Terminal window
\gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 \
-dPDFSETTINGS=/screen \
-dNOPAUSE -dBATCH \
-sOutputFile=compressed.pdf input.pdf

Vector Flattening

Flatten PDF content while retaining vector graphics and the original color space.

Terminal window
\gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 \
-dPDFSETTINGS=/ebook \
-dColorConversionStrategy=/LeaveColorUnchanged \
-dPreserveAnnots=false \
-dPreserveFlattenedNC=false \
-dNOINTERACTION -dNOPAUSE -dQUIET -dBATCH \
-sOutputFile=flattened-vector.pdf input.pdf

Annotation Flattening

Flatten annotations and page rotation into the PDF content.

Terminal window
qpdf --flatten-annotations=all --flatten-rotation input.pdf flattened-annotations.pdf

Structural Optimization

Linearize the PDF and optimize embedded images and unreferenced objects.

Terminal window
qpdf --linearize --optimize-images input.pdf optimized-structural.pdf

Image Optimization with Quality

Recompress images with a specified JPEG quality when optimization reduces file size.

Terminal window
qpdf --optimize-images --jpeg-quality=85 input.pdf optimized-images-quality.pdf
--jpeg-quality=(0-100)

PDF 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.

Terminal window
\gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 \
-sPAPERSIZE=letter \
-dFIXEDMEDIA \
-dPDFFitPage \
-dAutoRotatePages=/None \
-dModifiesPageSize=true \
-dNOPAUSE -dBATCH -dQUIET \
-sOutputFile=resized-letter.pdf input.pdf
-sPAPERSIZE=(letter | a4 | legal | ledger | ...)

Resize to Exact Dimensions

Resize PDF pages to exact dimensions in points while scaling and centering the original content to fit.

Terminal window
\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.pdf
Verify
pdfinfo -f 1 -l $(pdfinfo "resized-letter-exact.pdf" | awk '/Pages/ {print $2}') "resized-letter-exact.pdf" | grep -E "Page.*size:"
Letter = 612×792 points; 72 points = 1 inch.