IRONSOFTWAREHOME
PDF Compression
from ironpdf import *

pdf = PdfDocument("document.pdf")

# Quality parameter can be 1-100, where 100 is 100% of original quality
pdf.CompressImages(60)
pdf.SaveAs("document_compressed.pdf")

# Second optional parameter can scale down the image resolution according to its visible size in the PDF document. Note that this may cause distortion with some image configurations
pdf.CompressImages(90, True)
pdf.SaveAs("document_scaled_compressed.pdf")
pip install ironpdf
PDF Compression

PDF Compression

IronPDF for Python can reduce the file size of PDF documents by compressing embedded images using the CompressImages method, which accepts a quality level and an optional image-scaling parameter.

Getting Started

Load a PdfDocument from a file using PdfDocument(path), call CompressImages with the desired quality level, and save the result to a new file.

Understanding the Code

  • PdfDocument("document.pdf"): Opens the existing PDF for modification.
  • CompressImages(quality): Compresses all images in the document to the specified quality level. quality is an integer from 1 to 100, where 100 preserves the original quality and lower values reduce file size at the cost of image fidelity.
  • CompressImages(quality, scaleDownImages): The optional second boolean parameter, when set to True, additionally scales down image resolution based on each image's visible size in the PDF. This can produce significantly smaller files but may cause visual artifacts for some image types.
  • SaveAs(path): Saves the compressed PDF to the specified file path.

Choosing a Quality Level

QualityUse Case
90-100Near-lossless, minimal size reduction
60-80Good balance for most documents
30-50Small files for email or web distribution
1-29Maximum compression, significant quality loss
Learn to optimize PDFs with IronPDF for Python!

Ready to Get Started?

Version:2026.9just released

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

OR
bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried Iron Suite
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required
Python Module Download for PDF
Install with pip

Version: 2026.9

  1. Download and install Python 3.7+.
  2. Install pip from pypi.org if it isn't installed already.
  3. Execute the above command in the terminal.
Python PDF Module
Download Module

Version: 2026.9

Manually install into your project

  1. Download the package
  2. Run this command from the terminal
    pip install ironpdf-2026.9-py37-none-win_amd64.whi

Licenses from $999