Class CompressionMode
Specifies the compression strategy to use when reducing PDF file size.
Inheritance
Namespace: IronPdf
Assembly: IronPdf.dll
Syntax
public sealed class CompressionMode : Enum
The CompressionMode enumeration in IronPDF selects the compression strategy applied when a PDF is written to disk or stream.
Part of the IronPdf namespace, members are Automatic, FastMemory, and HighQuality (3 total). AdvancedCompressionOptions exposes this value alongside object-stream and image settings, so the choice trades runtime memory against output size on large documents.
See the PDF compression guide for tuning examples.
Fields
Automatic
Automatically selects the optimal compression method based on system capabilities. This is the default and recommended option for most scenarios.
Declaration
public const CompressionMode Automatic
Field Value
| Type | Description |
|---|---|
| CompressionMode |
Remarks
Behavior:
- First attempts to use HighQuality compression for maximum file size reduction.
- If disk access is restricted (e.g., limited permissions, sandboxed environment), automatically falls back to FastMemory.
When to Use:
Recommended for most applications where you want optimal compression but need to handle varying system environments gracefully.
FastMemory
Performs compression entirely in memory without any disk I/O operations.
Declaration
public const CompressionMode FastMemory
Field Value
| Type | Description |
|---|---|
| CompressionMode |
Remarks
Characteristics:
- Speed: Fastest compression method
- Security: No temporary files written to disk
- File Size: Produces larger files compared to HighQuality (no image resampling/downsampling)
- Disk I/O: Zero disk access required
When to Use:
- Compliance requirements mandate zero disk I/O (e.g., HIPAA, PCI-DSS)
- Processing sensitive documents that must not touch the filesystem
- Sandboxed or restricted environments without disk write permissions
- Performance is critical and file size is acceptable
Limitations:
Image optimization and JPEG quality settings are not applied in this mode.
HighQuality
Applies maximum compression using advanced optimization techniques. Requires temporary disk access but produces the smallest possible file size.
Declaration
public const CompressionMode HighQuality
Field Value
| Type | Description |
|---|---|
| CompressionMode |
Remarks
Characteristics:
- File Size: Smallest output files (maximum compression)
- Image Optimization: Applies JPEG resampling and downsampling based on quality settings
- Stream Compression: Uses maximum zlib compression on content streams
- Disk I/O: Requires writing temporary files to the system temp directory
When to Use:
- Archiving documents where file size is the primary concern
- Email attachments that must meet size restrictions
- Web delivery where bandwidth/storage costs are significant
- Long-term storage scenarios requiring minimal space
System Requirements:
Requires write permissions to the system temporary directory. If disk access fails, an exception will be thrown in explicit mode, or automatic fallback to FastMemory occurs in Automatic mode.
value__
Declaration
public int value__
Field Value
| Type | Description |
|---|---|
| System.Int32 |