Some test text!

Add layerkeyboard_arrow_down

Add a new PDF Layer in PHP

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

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

// Create a layer
$image_layer = Group::Create($doc, "Image Layer");
$cfg = Config::Create($doc, true);

// Add the new OCG to the list of layers that should appear in PDF viewer GUI.
$layer_order_array = $doc->CreateIndirectArray();

// Start a new 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.
$img = Image::Create($doc->GetSDFDoc(), $imagename);
$img->GetSDFObj()->Put("OC", $image_layer);
$writer->WritePlacedElement($builder->CreateImage($img, 300.0, 600.0, 200.0, -150.0));
$writer->End();   // save changes to the current page

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

Get the answers you need: Support


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.

Join our live demo to learn about use cases & capabilities for WebViewer

Learn more