DynaPDF Manual - Page 277
Previous Page 276 Index Next Page 278
Page 277 of 821
How to make content optional?
Page contents, such as text, images, and vector graphics can be associated with an OCG with
BeginLayer() / EndLayer(). Anything that is drawn between these function calls becomes part of the
layer or OCG.
Interactive objects such as Annotations and Form Fields can be added to a layer with
AddObjectToLayer(). However, interactive objects can be associated with exactly one layer at time.
In cases where the visibility should depend on more than one OCG it is possible to connect the
object with an Optional Content Membership Dictionary (OCMD). OCMDs accept an array of OCG
handles and a visibility expression that defines when the associated content should become visible
or invisible (see CreateOCMD() for further information). OCMDs can also be used with
BeginLayer(), e.g. if too many nested BeginLayer() calls would be required to achieve the same
Images and templates can be associated with an OCG or OCMD too. This can be useful if the object
must be drawn outside of the parent layers or to achieve more complex visibility expressions.
This function is implemented in an Ansi and Unicode compatible version. Unused OCGs will not be
written to the PDF file.
If the function succeeds the return value is the OCG handle, a value greater or equal zero. If the
function fails the return value is a negative error code.
// We use three layers in this example
SI32 oc1 = pdfCreateOCG(pdf, "Anything", true, true, oiAll);
SI32 oc2 = pdfCreateOCG(pdf, "Text and Annotations", true, true, oiAll);
SI32 oc3 = pdfCreateOCG(pdf, "Images", true, true, oiAll);
// The main layer controls the visibility of all three layers in this
pdfSetFont(pdf, "Arial", fsRegular, 12.0, true, cp1252);
char someText = "Some text with a link!!!";
pdfWriteText(pdf, 50.0, 50.0, someText);
double tw = pdfGetTextWidth(pdf, someText);
Previous topic: CreateOCG
Next topic: CreateOCMD