# Remove form fields This topic describes how to remove form fields from PDF file using the GroupDocs.Viewer Java API. If the output PDF file contains form fields, you can flatten them to reduce the file size. To remove form fields, set the `setRemoveFormFields()` property to `true` in [PdfOptimizationOptions](https://reference.groupdocs.com/viewer/java/com.groupdocs.viewer.options/pdfoptimizationoptions/). The following code snippet shows how to flatten form fields in the file: {{< tabs "Example1">}} {{< tab "Java" >}} ```java try (Viewer viewer = new Viewer("sample.docx")) { PdfViewOptions viewOptions = new PdfViewOptions(); viewOptions.setPdfOptimizationOptions(new PdfOptimizationOptions()); viewOptions.getPdfOptimizationOptions().setRemoveFormFields(true); viewer.view(viewOptions); } ``` {{}} {{}} The following image demonstrates the result: ![Remove fields](https://docs.groupdocs.com/viewer/java/images/pdf-rendering/optimization/optimization-pdf-remove-fields.png)