Some test text!

Discord Logo

Chat with us

PDFTron is now Apryse, learn more here.

Go / Guides / Add layer



PDFTron is now Apryse, learn more here.

Add a new PDF Layer in Go

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

doc := NewPDFDoc()

builder := NewElementBuilder()    // NewElementBuilder is used to build new Element objects
writer := NewElementWriter()      // NewElementWriter is used to write Elements to the page

// Create a layer
imageLayer := CreateLayer(doc, "Image Layer")
cfg = ConfigCreate(doc, true)

// Start a new page
page := doc.PageCreate()

// Add new content to the page and associate it with one of the layers.
img := ImageCreate(doc.GetSDFDoc(), imagname)
img.GetSDFObj().Put("OC", imageLayer.GetSDFObj())
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