DynaPDF Manual - Page 288
Previous Page 287 Index Next Page 289
Function Reference
Page 288 of 839
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
result.
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.
Remarks:
This function is implemented in an Ansi and Unicode compatible version. Unused OCGs will not be
written to the PDF file.
Return values:
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.
Example (C++):
pdfCreateNewPDF(pdf, "test_layer.pdf");
// 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);
pdfSetPageCoords(pdf, pcTopDown);
pdfAppend(pdf);
// The main layer controls the visibility of all three layers in this
// example.
pdfBeginLayer(pdf, oc1);
pdfBeginLayer(pdf, oc2);
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