Some test text!

Search
Hamburger Icon

Android / Guides / Add layer

Add a new PDF Layer in Android

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

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

// Create a layer
Group image_layer = Group.create(doc, "Image Layer");
Config cfg = 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.

Trial setup questions? Ask experts on Discord
Need other help? Contact Support
Pricing or product questions? Contact Sales