1PDFDoc doc = new PDFDoc();
2ElementBuilder builder = new ElementBuilder(); // ElementBuilder is used to build new Element objects
3ElementWriter writer = new ElementWriter(); // ElementWriter is used to write Elements to the page
4
5// Create a layer
6Group image_layer = Group.Create(doc, "Image Layer");
7Config cfg = Config.Create(doc, true);
8cfg.SetName("Default");
9
10// Add the new OCG to the list of layers that should appear in PDF viewer GUI.
11Obj layer_order_array = doc.CreateIndirectArray();
12cfg.SetOrder(layer_order_array);
13layer_order_array.PushBack(image_layer.GetSDFObj());
14
15// Start a new page
16Page page = doc.PageCreate();
17writer.Begin(page); // begin writing to this page
18
19// Add new content to the page and associate it with the layer.
20Image img = Image.Create(doc.GetSDFDoc(), imagename);
21img.GetSDFObj().Put("OC", image_layer.GetSDFObj());
22writer.WritePlacedElement(builder.CreateImage(img, 300, 600, 200, -150));
23writer.End(); // save changes to the current page
24doc.PagePushBack(page);