# Convert to grayscale This topic describes how to convert PDF file to grayscale using the GroupDocs.Viewer Java API. 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 [setConvertToGrayScale()](https://reference.groupdocs.com/viewer/java/com.groupdocs.viewer.options/Pdfoptimizationoptions/#setConvertToGrayScale-boolean-) method to `true`. The following code snippet shows how to convert a PDF file to grayscale: {{< tabs "Example1">}} {{< tab "Java" >}} ```java try (Viewer viewer = new Viewer("sample.docx")) { PdfViewOptions viewOptions = new PdfViewOptions(); viewOptions.setPdfOptimizationOptions(new PdfOptimizationOptions()); viewOptions.getPdfOptimizationOptions().setConvertToGrayScale(true); viewer.view(viewOptions); } ``` {{}} {{}} The following image demonstrates the result: ![Convert to grayscale](https://docs.groupdocs.com/viewer/java/images/pdf-rendering/optimization/optimization-pdf-convert-grayscale.png)