What is Optional Content?
While most users call them "Layers," the official PDF specification refers to them as **Optional Content Groups (OCGs)**. An OCG is essentially a "tag" that you apply to specific pieces of PDF code. For example, you can take all the lines and text that make up the "Level 2 Floor Plan" and tell the PDF: "This content belongs to OCG #1."
A document can then have an **Optional Content Configuration Dictionary (OCCD)**. This is a master control panel that defines how those OCGs behave. It tells the PDF reader things like: "Start with OCG #1 hidden" or "Only show OCG #2 if the user chooses 'Spanish' in the settings."
How it Differs from Standard Hiding
- The Data is Still There: Optional content does NOT remove data from the file. It just tells the software not to "Paint" it right now. This is why OCGs are not safe for redaction.
- Logic Independent of Pages: An OCG can span across multiple pages. You can have a "Header" OCG that exists on every page, and turning it off in the sidebar hides it everywhere instantly.
- State Management: OCGs can be programmed with complex states, such as "Always print this, but never show it on screen." This is perfect for instructional watermarks or internal barcoding. }
- OCG (The Group): The container that holds a list of objects.
- OCMD (The Membership Dictionary): Advanced logic that says "Show this only if Group A is ON AND Group B is OFF." This is how you create complex interactive dependencies.
- Default Configuration:** The "Initial State" of the file when it is first opened by a user.
- When your "Layers" are not behaving correctly across different PDF readers.
- When you need to create complex "And/Or" logic for content visibility (using OCMDs).
- When you need to ensure that certain information is "Non-Printing" but always visible on screen.
- **Pro Tip:** Always check the "Locked" status of an OCG. You can lock a layer so that the user sees it but cannot turn it off, which is useful for legal notices or copyright watermarks.
Internal Components of OCG
The "Intent" Field
OCGs can have an "Intent" tag. For example, an intent of `View` means the layer is for the user to look at. An intent of `Design` means it is for professional CAD software. This helps different programs understand *why* the content is optional and how they should treat it.
Real-World Examples
An automotive engineer creates a 3D blueprint for an engine block. They use **Optional Content Groups** to organize the parts. They create an OCG for the "Pistons," one for the "Crankshaft," and one for the "Fuel Lines." Because they use OCGs rather than just separate files, a mechanic can open the PDF and "isolate" the Pistons to see exactly how they fit into the assembly without the other parts blocking the view.
A large multinational corporation releases its annual "Sustainability Report." To make the file more engaging, they add an "Interactive Map" that shows where all their carbon-neutral factories are located. Each country has its own **Optional Content Group**. When a user clicks on "Germany" in the table of contents, a **JavaScript Action** triggers the OCG for Germany to turn "ON," making the factory locations for that specific country appear on the map instantly.