IRONSOFTWAREHOME
PDF Compression

import com.ironsoftware.ironpdf.*;
import java.io.IOException;  
import java.nio.file.Paths;

PdfDocument pdf = PdfDocument.fromFile(Paths.get("assets/document.pdf"));  
  
// Valid image compression values range from 1 to 100, where 100 represents 100% of the  
// original image quality.  
pdf.compressImages(60);  
pdf.saveAs(Paths.get("assets/document_compressed.pdf"));  
  
// The 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(Paths.get("assets/document_scaled_compressed.pdf"));
mvn install
PDF Compression

PDF Compression

IronPDF can compress the file size of PDFs by reducing the size of any embedded images. For this purpose, developers can invoke the PdfDocument class's compressImages method to reduce the file size of PDFs that incorporate large images and other graphical elements. This creates great savings in storage space, time, and costs in transporting PDFs efficiently across email and other communication channels.

The compressImages method accepts integer values between 0 and 100, which indicate the targeted quality percentage for embedded images. Moreover, the rules for working with this method are similar to the rules for optimizing file sizes for lossy image types like JPEG. A value of 100 indicates that images must retain their original quality (no loss), and lower values indicate lower original quality thresholds.

The code example featured in the IronPDF image compression guide produces two new PDFs from the same original PDF using different image compression qualities. The first one produces a PDF whose images lose much of their original quality. Quality values below 70 will typically produce PDFs whose images are of very low quality but whose file sizes are smaller by a significant margin. The second PDF is produced with a higher quality threshold (90%). This yields a PDF with images of much higher quality but with a much smaller reduction in file size compared to the first.

The ideal quality values will vary based on user requirements. Some experimentation may be needed to find the value that produces the smallest file size while keeping image quality acceptable.

Learn How to Compress PDFs in Java with IronPDF
View on GitHub

Ready to Get Started?

Version:2026.8just 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 IronPDF
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
Java Maven Library for PDF
Install with Maven

Version: 2026.8

<dependency>
   <groupId>com.ironsoftware</groupId>
   <artifactId>ironpdf</artifactId>
   <version>2026.8.2</version>
</dependency>
https://central.sonatype.com/artifact/com.ironsoftware/ironpdf/2026.8.2
or
Java PDF JAR
Download JAR

Version: 2026.8

Manually install into your project