Selectively browse PDF OCG layers in Android

A PDF OCG (Optional Content Groups) dictionary represents a collection of graphic objects that can be made visible or invisible. Any graphic content of the PDF can be made optional, including page contents, XObjects, and annotations.

The PdfLayerDialogFragment allows you to browse OCG layers associated with the document. You can selectively render layers based on their states. In a tree view of nested layers, if the parent layer is hidden, the child layers are automatically hidden as well. If the parent layer is visible, child layers can be made visible or hidden.

Apryse Docs Image

Show the OCG layer browser

1public void show(PDFViewCtrl pdfViewCtrl, FragmentManager fragmentManager) {
2 PdfLayerDialogFragment pdfLayerDialogFragment = PdfLayerDialogFragment.newInstance();
3 pdfLayerDialogFragment.setPdfViewCtrl(pdfViewCtrl);
4 pdfLayerDialogFragment.setStyle(DialogFragment.STYLE_NO_TITLE, ((ToolManager) pdfViewCtrl.getToolManager()).getTheme());
5 if (fragmentManager != null) {
6 pdfLayerDialogFragment.show(fragmentManager, "pdf_layer_dialog");
7 }
8}

Did you find this helpful?

Trial setup questions?

Ask experts on Discord

Need other help?

Contact Support

Pricing or product questions?

Contact Sales