# Optimize a PDF file for a browser This topic describes how to optimize PDF file using the GroupDocs.Viewer Java API for web browser or to reduce size. This optimization allows a browser to display the first pages of a PDF file when you open the document, instead of waiting for the entire file to download. The following code snippet shows how to optimize a PDF file for browser: {{< tabs "Example1">}} {{< tab "Java" >}} ```java try (Viewer viewer = new Viewer("sample.docx")) { PdfViewOptions viewOptions = new PdfViewOptions(); viewOptions.setPdfOptimizationOptions(new PdfOptimizationOptions()); viewOptions.getPdfOptimizationOptions().setLinearize(true); viewer.view(viewOptions); } ``` {{}} {{}}