OptimizationOptions Class
Contains PDF optimization settings.
Declaration
public class OptimizationOptions extends JavaObject
Remarks
Use OptimizationOptions to apply multiple optimization techniques. For example, you can remove unnecessary document elements and compress images in a single operation. Pass a configured OptimizationOptions object to the PdfDocument.optimize() method to optimize the PDF document.
Refer to the following help topic for additional information: Optimize PDF Documents.
The following code snippet removes metadata, attachments, and thumbnails. It also compresses images to reduce the PDF file size.
package pdf;
import com.devexpress.docs.pdf.*;
import java.nio.channels.*;
import java.nio.file.*;
public class Main {
public static void main(String[] args) throws Exception {
try (FileChannel channel = FileChannel.open(Path.of("Document.pdf"));
PdfDocument pdfDocument = new PdfDocument(channel)) {
// Configure image compression.
ImageCompressionOptions imageOptions = new ImageCompressionOptions();
imageOptions.setCompressionType(ImageCompressionType.JPEG);
imageOptions.setJpegQuality(80);
// Configure optimization options.
OptimizationOptions options = new OptimizationOptions();
options.setRemoveMetadata(true);
options.setRemoveAttachments(true);
options.setRemoveThumbnails(true);
options.setImageCompressionOptions(imageOptions);
// Optimize the PDF document.
pdfDocument.optimize(options);
try (WritableByteChannel writableByteChannel =
FileChannel.open(Path.of("Document_Optimized.pdf"),
StandardOpenOption.CREATE,
StandardOpenOption.WRITE,
StandardOpenOption.TRUNCATE_EXISTING)) {
pdfDocument.save(writableByteChannel);
}
}
}
}
Inherited Members
Inheritance
OptimizationOptions()
Initializes a new instance of the OptimizationOptions class.
Declaration
public OptimizationOptions()
Methods
getImageCompressionOptions() Method
Returns image compression options.
Declaration
public ImageCompressionOptions getImageCompressionOptions()
Returns
| Type | Description |
|---|---|
| ImageCompressionOptions | Image compression options. |
getRemoveAttachments() Method
Returns whether to remove embedded files and attachments.
Declaration
public boolean getRemoveAttachments()
Returns
| Type | Description |
|---|---|
| boolean |
|
getRemoveBookmarkOutlines() Method
Returns whether to remove bookmark outlines.
Declaration
public boolean getRemoveBookmarkOutlines()
Returns
| Type | Description |
|---|---|
| boolean |
|
getRemoveJavaScriptActions() Method
Returns whether to remove JavaScript actions.
Declaration
public boolean getRemoveJavaScriptActions()
Returns
| Type | Description |
|---|---|
| boolean |
|
getRemoveLogicalStructure() Method
Returns whether to remove logical structure information used for accessibility.
Declaration
public boolean getRemoveLogicalStructure()
Returns
| Type | Description |
|---|---|
| boolean |
|
getRemoveMetadata() Method
Returns whether to remove document metadata.
Declaration
public boolean getRemoveMetadata()
Returns
| Type | Description |
|---|---|
| boolean |
|
getRemoveThumbnails() Method
Returns whether to remove page thumbnails.
Declaration
public boolean getRemoveThumbnails()
Returns
| Type | Description |
|---|---|
| boolean |
|
setImageCompressionOptions(ImageCompressionOptions value) Method
Sets image compression options.
Declaration
public void setImageCompressionOptions(ImageCompressionOptions value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | ImageCompressionOptions | Image compression options. |
setRemoveAttachments(boolean value) Method
Sets whether to remove embedded files and attachments.
Declaration
public void setRemoveAttachments(boolean value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | boolean |
|
setRemoveBookmarkOutlines(boolean value) Method
Sets whether to remove bookmark outlines.
Declaration
public void setRemoveBookmarkOutlines(boolean value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | boolean |
|
setRemoveJavaScriptActions(boolean value) Method
Sets whether to remove JavaScript actions.
Declaration
public void setRemoveJavaScriptActions(boolean value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | boolean |
|
setRemoveLogicalStructure(boolean value) Method
Sets whether to remove logical structure information used for accessibility.
Declaration
public void setRemoveLogicalStructure(boolean value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | boolean |
|
setRemoveMetadata(boolean value) Method
Sets whether to remove document metadata.
Declaration
public void setRemoveMetadata(boolean value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | boolean |
|
setRemoveThumbnails(boolean value) Method
Sets whether to remove page thumbnails.
Declaration
public void setRemoveThumbnails(boolean value)
Parameters
| Name | Type | Description |
|---|---|---|
| value | boolean |
|