Convert to grayscale

On this page

To speed up the printing of a PDF file and reduce its size, you can convert it from RGB color space to grayscale.

To convert a PDF file to grayscale, set the convert_to_gray_scale property to True.

The following code snippet shows how to convert a PDF file to grayscale:

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

def convert_to_grayscale():
    # Load document
    with Viewer("sample.docx") as viewer:
        viewOptions = PdfViewOptions("convert_to_grayscale/grayscale_output.pdf")
        viewOptions.pdf_optimization_options = PdfOptimizationOptions()
        viewOptions.pdf_optimization_options.convert_to_gray_scale = True

        viewer.view(viewOptions)

if __name__ == "__main__":
    convert_to_grayscale()

sample.docx is the sample file used in this example. Click here to download it.

The following image demonstrates the result:

Convert to grayscale

On this page

Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.