Some test text!

menu
search
Add layerkeyboard_arrow_down

Add a new PDF Layer

To add a PDF layer or OCG (optional content group) to a new document.

PDFDoc doc;
ElementBuilder builder; // ElementBuilder is used to build new Element objects
ElementWriter writer;   // ElementWriter is used to write Elements to the page  

// Create a layer
OCG::Group image_layer = OCG::Group::Create(doc, "Image Layer");
OCG::Config cfg = OCG::Config::Create(doc, true);
cfg.SetName("Default");

// Add the new OCG to the list of layers that should appear in PDF viewer GUI.
Obj layer_order_array = doc.CreateIndirectArray();
cfg.SetOrder(layer_order_array);
layer_order_array.PushBack(image_layer.GetSDFObj());

// Start a new page
Page page = doc.PageCreate();
writer.Begin(page); // Begin writing to the page

// Add new content to the page and associate it with one of the layers. 
Image img = Image::Create(doc.GetSDFDoc(), imagename);
img.GetSDFObj().Put("OC", image_layer.GetSDFObj());
writer.WritePlacedElement(builder.CreateImage(img, 300, 600, 200, -150));
writer.End();    // save changes to the current page
doc.PagePushBack(page);

PDF layers (OCG)
Full sample code which demonstrates how to create, extract, render PDF layers.

Get the answers you need: Support

close

Free Trial

Get unlimited trial usage of PDFTron SDK to bring accurate, reliable, and fast document processing capabilities to any application or workflow.

Select a platform to get started with your free trial.

Unlimited usage. No email address required.

PDFTron Receives USD$71 Million Growth Investment Led By Silversmith Capital Partners

Learn more
close