# PDFOptimizer Class

> Implementation of the PDF Optimizer function.

- Product: Adobe PDF Library 18
- Language: Java
- Version: APDFL18.0.5PlusP2e
- HTML page: https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/PDFOptimizer
- Version index: https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/llms.txt

```java
class PDFOptimizer
```

**Namespace:** `com::datalogics::PDFL`

## Description

Implementation of the PDF Optimizer function. Use the PDFOptimizer object to accumulate options for the Optimization, and to Optimize documents.

**Uses types:** [`CancelProc`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/CancelProc.md), [`Document`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Document.md), [`JavaStreamFile`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/JavaStreamFile.md), [`ProgressMonitor`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/ProgressMonitor.md)

## Constructors

### PDFOptimizer

```java
com.datalogics.PDFL.PDFOptimizer.PDFOptimizer()
```

*constructor*

Construct a CPDFOptimizer, with default Options.

## Methods

### delete

```java
synchronized void com.datalogics.PDFL.PDFOptimizer.delete(Boolean disposing)
```

*protected*

**Parameters**

- `disposing` (`Boolean`)

**Returns:** `synchronized void`

### delete

```java
synchronized void com.datalogics.PDFL.PDFOptimizer.delete()
```

**Returns:** `synchronized void`

### finalize

```java
void com.datalogics.PDFL.PDFOptimizer.finalize()
```

*protected*

**Returns:** `void`

### getCompressionQuality

```java
CompressQuality com.datalogics.PDFL.PDFOptimizer.getCompressionQuality(CompressImageType type)
```

**Parameters**

- `type` (`CompressImageType`): The image color type (Color, Gray, or BW) to query.

**Returns:** `CompressQuality`

The compression quality level for the specified color model.

Get the value of the Compression Quality for a given color model.

### getMajorVersion

```java
short com.datalogics.PDFL.PDFOptimizer.getMajorVersion()
```

**Returns:** `short`

The major PDF version number, or 0 if the Optimizer will decide.

Get the value of the Major Version of the optimized document.

### getMaxResolution

```java
int com.datalogics.PDFL.PDFOptimizer.getMaxResolution(CompressImageType type)
```

**Parameters**

- `type` (`CompressImageType`): The image color type (Color, Gray, or BW) to query.

**Returns:** `int`

The maximum resolution in DPI above which images will be downsampled.

Get the value of the Max DPI for a given color model.

### getMinorVersion

```java
short com.datalogics.PDFL.PDFOptimizer.getMinorVersion()
```

**Returns:** `short`

The minor PDF version number.

Get the value of the Minor Version of the optimized document.

### getObjectCompression

```java
ObjectCompressionType com.datalogics.PDFL.PDFOptimizer.getObjectCompression()
```

**Returns:** `ObjectCompressionType`

The current object compression type setting.

Get the value of the Object Compression of the optimized document.

### getOption

```java
boolean com.datalogics.PDFL.PDFOptimizer.getOption(OptimizerOption option)
```

**Parameters**

- `option` (`OptimizerOption`): The optimization option to query.

**Returns:** `boolean`

true if the option is enabled, false if it is disabled.

Get the value of a single Optimizer Option.

### getRecompressionType

```java
CompressionType com.datalogics.PDFL.PDFOptimizer.getRecompressionType(CompressImageType type)
```

**Parameters**

- `type` (`CompressImageType`): The image color type (Color, Gray, or BW) to query.

**Returns:** `CompressionType`

The compression type that will be applied to images of the specified color model.

Get the value of the Recompression Type for a given color model.

### getResampleToResolution

```java
int com.datalogics.PDFL.PDFOptimizer.getResampleToResolution(CompressImageType type)
```

**Parameters**

- `type` (`CompressImageType`): The image color type (Color, Gray, or BW) to query.

**Returns:** `int`

The target resolution in DPI to which images will be downsampled.

Get the value of the Resample To DPI for a given color model.

### optimize

```java
void com.datalogics.PDFL.PDFOptimizer.optimize(Document doc, javax.imageio.stream.ImageOutputStream stream)
```

**Parameters**

- `doc` ([`Document`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Document.md))
- `stream` (`javax.imageio.stream.ImageOutputStream`)

**Returns:** `void`

### optimize

```java
void com.datalogics.PDFL.PDFOptimizer.optimize(Document doc, javax.imageio.stream.ImageOutputStream stream, ProgressMonitor progressMonitor, CancelProc cancelProc)
```

**Parameters**

- `doc` ([`Document`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Document.md))
- `stream` (`javax.imageio.stream.ImageOutputStream`)
- `progressMonitor` ([`ProgressMonitor`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/ProgressMonitor.md))
- `cancelProc` ([`CancelProc`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/CancelProc.md))

**Returns:** `void`

### optimize

```java
void com.datalogics.PDFL.PDFOptimizer.optimize(Document document, JavaStreamFile dest)
```

**Parameters**

- `document` ([`Document`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Document.md)): The document to optimize.
- `dest` ([`JavaStreamFile`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/JavaStreamFile.md)): The stream file handle to write the optimized document to.

**Returns:** `void`

Perform the Optimization of a single document, saving the result to a stream.

### optimize

```java
void com.datalogics.PDFL.PDFOptimizer.optimize(Document document, JavaStreamFile dest, ProgressMonitor progressMonitor, CancelProc cancelProc)
```

**Parameters**

- `document` ([`Document`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Document.md)): The document to optimize.
- `dest` ([`JavaStreamFile`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/JavaStreamFile.md)): The stream file handle to write the optimized document to.
- `progressMonitor` ([`ProgressMonitor`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/ProgressMonitor.md)): An optional progress monitor callback, or NULL.
- `cancelProc` ([`CancelProc`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/CancelProc.md)): An optional cancellation callback, or NULL.

**Returns:** `void`

Perform the Optimization of a single document, saving the result to a stream.

### optimize

```java
void com.datalogics.PDFL.PDFOptimizer.optimize(Document document, String newPath)
```

**Parameters**

- `document` ([`Document`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Document.md)): The document to optimize.
- `newPath` (`String`): The file system path where the optimized document will be saved.

**Returns:** `void`

Perform the Optimization of a single document, saving the result in a new file.

### optimize

```java
void com.datalogics.PDFL.PDFOptimizer.optimize(Document document, String newPath, ProgressMonitor progressMonitor, CancelProc cancelProc)
```

**Parameters**

- `document` ([`Document`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/Document.md)): The document to optimize.
- `newPath` (`String`): The file system path where the optimized document will be saved.
- `progressMonitor` ([`ProgressMonitor`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/ProgressMonitor.md)): An optional progress monitor callback, or NULL.
- `cancelProc` ([`CancelProc`](https://docs.datalogics.com/apdfl18/Java/APDFL18.0.5PlusP2e/class/CancelProc.md)): An optional cancellation callback, or NULL.

**Returns:** `void`

Perform the Optimization of a single document, saving the result in a new file.

### setCompressionQuality

```java
void com.datalogics.PDFL.PDFOptimizer.setCompressionQuality(CompressImageType type, CompressQuality value)
```

**Parameters**

- `type` (`CompressImageType`): The image color type (Color, Gray, or BW) to set.
- `value` (`CompressQuality`): The compression quality level to apply.

**Returns:** `void`

Set the value for the Compression Quality for a given color model. Any image that recompressed, regardless of the reason, will use this Quality for the Quality value of the specific compression type.

### setMajorVersion

```java
void com.datalogics.PDFL.PDFOptimizer.setMajorVersion(short major)
```

**Parameters**

- `major` (`short`): The major PDF version number.

**Returns:** `void`

Set the value for the Major Version for the optimized document.

### setMaxResolution

```java
void com.datalogics.PDFL.PDFOptimizer.setMaxResolution(CompressImageType type, int value)
```

**Parameters**

- `type` (`CompressImageType`): The image color type (Color, Gray, or BW) to set.
- `value` (`int`): The maximum resolution in DPI.

**Returns:** `void`

Set the value for the Max DPI for a given color model. Any image above this resolution will be down sampled, if the Downsampling option is true for this color model.

### setMinorVersion

```java
void com.datalogics.PDFL.PDFOptimizer.setMinorVersion(short minor)
```

**Parameters**

- `minor` (`short`): The minor PDF version number.

**Returns:** `void`

Set the value for the Minor Version for the optimized document.

### setObjectCompression

```java
void com.datalogics.PDFL.PDFOptimizer.setObjectCompression(ObjectCompressionType objectCompression)
```

**Parameters**

- `objectCompression` (`ObjectCompressionType`): The desired object compression type.

**Returns:** `void`

Set the value for the Object Compression for the optimized document.

### setOption

```java
void com.datalogics.PDFL.PDFOptimizer.setOption(OptimizerOption option, boolean value)
```

**Parameters**

- `option` (`OptimizerOption`): The optimization option to set.
- `value` (`boolean`): true to enable the option, false to disable it.

**Returns:** `void`

Set the value of a single Optimizer option.

### setRecompressionType

```java
void com.datalogics.PDFL.PDFOptimizer.setRecompressionType(CompressImageType type, CompressionType value)
```

**Parameters**

- `type` (`CompressImageType`): The image color type (Color, Gray, or BW) to set.
- `value` (`CompressionType`): The compression type to apply.

**Returns:** `void`

Set the value for the recompression Type for a given color model. Any image that is downsampled will be compressed using this method, if the Downsampling option is true for this color model. Any image that is not downsampled, will be converted to this compression type, if it is not already compressed in this type, and the Recompression option for this color model is true.

### setResampleToResolution

```java
void com.datalogics.PDFL.PDFOptimizer.setResampleToResolution(CompressImageType type, int value)
```

**Parameters**

- `type` (`CompressImageType`): The image color type (Color, Gray, or BW) to set.
- `value` (`int`): The target resolution in DPI.

**Returns:** `void`

Set the value for the Resample To DPI for a given color model. Any image will be downsampled to this resolution, if the Downsampling option is true for this color model.
