PdfOptimizationOptions class

PdfOptimizationOptions class

Represents PDF optimization options to apply to the output PDF file.

For details and code samples, see the documentation page.

The PdfOptimizationOptions type exposes the following members:

Constructors

Constructor Description
init Initializes a new instance of PdfOptimizationOptions with default MaxResolution of 300 and ImageQuality of 100.

Properties

Property Description
compress_images The compress_images property enables compressing images in the output PDF file.
convert_to_gray_scale The property enables converting the output PDF file to grayscale.
image_quality The image quality in the output PDF file, expressed as a percentage.
lineriaze The property enables optimization of the output PDF file for viewing online with a web browser.
max_resolution The maximum resolution in the output PDF file.
optimize_spreadsheets The property enables optimization of spreadsheets in the PDF files. The default value is False.
remove_annotations The property enables removing annotations from the output PDF file.
remove_form_fields The property enables removing form fields from a PDF file.
remove_unused_objects The property removes unused (orphaned) objects from a PDF file, decreasing the output size when set to True.
remove_unused_streams The property removes unused (orphaned) streams from a PDF file, which are still referenced from the resource dictionary of the page but never used in the page contents.
resize_images The property that enables setting the maximum resolution in the output PDF file.
subset_fonts The property indicates whether fonts are subset in the output PDF file.

Example

from groupdocs.viewer import Viewer
from groupdocs.viewer.options import PdfViewOptions, PdfOptimizationOptions

def remove_unused_resources():
    view_options_1 = PdfViewOptions("remove_unused_resources/removed_unused_objects.pdf")
    view_options_1.pdf_optimization_options = PdfOptimizationOptions()
    view_options_1.pdf_optimization_options.remove_unused_objects = True

    view_options_2 = PdfViewOptions("remove_unused_resources/removed_unused_streams.pdf")
    view_options_2.pdf_optimization_options = PdfOptimizationOptions()
    view_options_2.pdf_optimization_options.remove_unused_streams = True

    with Viewer("sample.pdf") as viewer:
        viewer.view(view_options_1)
        viewer.view(view_options_2)

if __name__ == "__main__":
    remove_unused_resources()

See Also