Components for Developers
© 2000-2016, Two Pilots

PDF Library   Virtual Printer   Converters   Squirrel   HTML_QuickForm   Design Service

Two Pilots blog

Layers (Optional Content Groups)

Layers or as they are more formally known Optional Content Groups (OCG) is representing a collection of graphics that can be made visible or invisible dynamically by users of viewer applications. (This ca­pability is useful in items such as CAD drawings, maps, and multi-language documents) With the introduction of PDF version 1.5 came the concept of Layers. Form and image and annotations can be made optional too.

A group is assigned a state, which is either ON or OFF. States can be set programmatically or through the viewer user interface to change the visibility of content. In the typical case, content belonging to a group is visible when the group is ON and invisible when it is OFF. When a piece of optional content in a PDF file is determined to be hidden, the content is not drawn.

You may see all layers in PDF document on Layers tab. (for Adobe Reader) Go into the “View” menu and select “Navigation Tabs” and then choose “Layers”.J. Cole: 4 Your Eyez Only streaming

So this gives us an instruction on how to create Layered PDFs within PDF Creator Pilot.  In our example we’ve created a PDF with several layers. (example for VBScript)

' create pdf library object
Set PDF = CreateObject("PDFCreatorPilot.PDFDocument4")

' initialize PDF Engine
PDF.SetLicenseData "demo@demo", "demo"

' set document title
PDF.SetTitle "PDF with Layers", 1

'  For creating PDF with layers, we need create named content group. For every layer –
' individual group:
groupIndex = PDF.CreateContentGroup("Text Optional Content Group")

' Then you need to add content in layer. Sections of content in the PDF document can be made
' optional by enclosing between the marked-content operators BeginMarkedContent and
' EndMarkedContent. Between this operators you may draw graphic shapes, images, forms,
' annotations or text:

'  Text content group example:
PDF.BeginMarkedContent groupIndex
PDF.ShowTextAt 10, 40, "Hello, optional content group!"

'  Image content group example:
img = PDF.AddImageFromFile(L"image.jpg")
PDF.BeginMarkedContent groupIndex
PDF.ShowImage img, 150, 100

'  Annotation content group example:
PDF.BeginMarkedContent groupIndex
PDF.AddUnicodeTextAnnotation 10, 10, "Title", "Some text goes here..."

'   You may combine content of this group. For example,
PDF.BeginMarkedContent groupIndex
PDF.ShowTextAt 10, 40, "Hello, optional content group!"
PDF.AddEditBox 50, 210, 150, 250, "edt1"
PDF.SetColor 0.0, 0.9f, 0.0, 0.0
PDF.DrawEllipse 100, 200, 200, 300

' finalize document generation
PDF.SaveToFile "PdfWithContentGroups.pdf", true

' disconnect from library
Set PDF = Nothing

Hopefully from the example code and the example PDFs you should see how useful Layers can be.

Here you can download examples of PDF documents created by PDF Creator Pilot:

Artem Golubnichenko
Project Manager of Virtual Printer

Leave a Reply

PDF Library   Virtual Printer   Converters   Squirrel   HTML_QuickForm   Design Service


Support | Blog | Forum | Contacts | About | Site map

© 2000-2016, Two Pilots