Some test text!

Discord Logo

Chat with us

PDFTron is now Apryse, learn more here.

iOS / Guides / Show/hide layers


PDFTron is now Apryse, learn more here.

Show or hide PDF layers on iOS

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 PTPDFLayerViewController allows you to browse OCG layers associated with the document being viewed by a PTPDFViewCtrl. You can selectively render layers based on their states.

PDF layer browser.

The PDF layer control is part of the Tools library, so make sure you have added the Tools library to your project .

Show the OCG layer browser

To create a new PDF layer view controller instance and display it from another view controller, supply a PTPDFViewCtrl instance to the PTPDFLayerViewController designated initializer:

// Initialize layer view controller with a PTPDFViewCtrl instance.
let pdfLayerViewController = PTPDFLayerViewController(pdfViewCtrl: pdfViewCtrl)

let navigationController = UINavigationController(rootViewController: pdfLayerViewController)
if ( UIDevice.current.userInterfaceIdiom == .pad ) {
    navigationController.modalPresentationStyle = .popover
    navigationController.popoverPresentationController?.barButtonItem = layerButton

self.present(navigationController, animated: true, completion: nil)
The PDF layer view controller must be pushed onto a navigation controller's stack before being shown.
Presenting on iPads:
The PDF layer view controller is designed to be presented in a popover on iPads. To do so, you must provide the PTPDFLayerViewController's UIPopoverPresentationController with either: OR as in the example above.

Get the answers you need: Support