Which is the best way to create a PDF document with optional content groups or "Layers"?
Estimated Reading Time: 1 MinutesOptional Content Groups (OCGs) are a feature for selectively controlling the visibility of content in the PDF document. OCGs permits content to be made visible or invisible, based on switch settings when being viewed in Adobe Acrobat or other viewing tools. See Section 8.11, “Optional Content,” in the ISO 32000 Reference.
Optional Content, or “layers,” are a useful way to customize the presentation of information when displaying a PDF file. For example, you could create a brochure with multiple layers offering the same content but in different languages. The first layer would be the blank background page. The resulting PDF file could be set up, with some extra program code, to select the appropriate layer with French or Spanish or English, depending on the language of the reader, and then display that language in the PDF file.
Basically, it consists of an Optional Content Properties Dictionary added to the document root. This dictionary contains an array of Optional Content Groups (OCGs), each describing a set of information and each of which may be individually displayed or suppressed, plus a set of Optional Content Configuration Dictionaries, which give the status (Displayed or Suppressed) of the given OCGs. Finally, within any content stream, marking operators may in turn be surrounded by a new set of operators, declaring them to be content of a given Optional Content Group.
There is complete support for Optional Content groups in APDFL at the PDFEdit level. See the PDFMakeOCGVisible sample (c++) and the ChangeLayerConfiguration (.NET and Java) for demonstrations.