Skip to main content

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

com.devexpress.system.JavaObject.clone()
com.devexpress.system.JavaObject.equals(java.lang.Object)
com.devexpress.system.JavaObject.hashCode()
com.devexpress.system.JavaObject.initFields()
com.devexpress.system.JavaObject.memberwiseClone()
com.devexpress.system.JavaObject.toString()
java.lang.Object.finalize()
java.lang.Object.getClass()
java.lang.Object.notify()
java.lang.Object.notifyAll()
java.lang.Object.wait()
java.lang.Object.wait(long)
java.lang.Object.wait(long,int)

Inheritance

Object
com.devexpress.system.JavaObject
OptimizationOptions

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

true to remove embedded files and attachments; otherwise, false.

getRemoveBookmarkOutlines() Method

Returns whether to remove bookmark outlines.

Declaration

public boolean getRemoveBookmarkOutlines()

Returns

Type Description
boolean

true to remove bookmarks outlines; otherwise, false.

getRemoveJavaScriptActions() Method

Returns whether to remove JavaScript actions.

Declaration

public boolean getRemoveJavaScriptActions()

Returns

Type Description
boolean

true to remove JavaScript actions; otherwise, false.

getRemoveLogicalStructure() Method

Returns whether to remove logical structure information used for accessibility.

Declaration

public boolean getRemoveLogicalStructure()

Returns

Type Description
boolean

true to remove logical structure information; otherwise, false.

getRemoveMetadata() Method

Returns whether to remove document metadata.

Declaration

public boolean getRemoveMetadata()

Returns

Type Description
boolean

true to remove document metadata; otherwise, false.

getRemoveThumbnails() Method

Returns whether to remove page thumbnails.

Declaration

public boolean getRemoveThumbnails()

Returns

Type Description
boolean

true to remove page thumbnails; otherwise, false.

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

true to remove embedded files and attachments; otherwise, false.

setRemoveBookmarkOutlines(boolean value) Method

Sets whether to remove bookmark outlines.

Declaration

public void setRemoveBookmarkOutlines(boolean value)

Parameters

Name Type Description
value boolean

true to remove bookmarks outlines; otherwise, false.

setRemoveJavaScriptActions(boolean value) Method

Sets whether to remove JavaScript actions.

Declaration

public void setRemoveJavaScriptActions(boolean value)

Parameters

Name Type Description
value boolean

true to remove JavaScript actions; otherwise, false.

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

true to remove logical structure information; otherwise, false.

setRemoveMetadata(boolean value) Method

Sets whether to remove document metadata.

Declaration

public void setRemoveMetadata(boolean value)

Parameters

Name Type Description
value boolean

true to remove document metadata; otherwise, false.

setRemoveThumbnails(boolean value) Method

Sets whether to remove page thumbnails.

Declaration

public void setRemoveThumbnails(boolean value)

Parameters

Name Type Description
value boolean

true to remove page thumbnails; otherwise, false.