DynaPDF Manual - Page 269

Previous Page 268   Index   Next Page 270

Function Reference
Page 269 of 770
Return values:
If the function succeeds the return value is the action handle, a value greater or equal zero. If the
function fails the return value is a negative error code.
Example (C++):
This example creates a document in two languages. The text for the different languages is placed into
separate layers. A JavaScript Action selects the correct layer depending on the viewer language when
opening the file. It is also possible to change the language with two bookmarks. The bookmarks are
connected with a SetOCGState action that simply toggles the layer states from on to off or vice versa.
SI32 PDF_CALL PDFError(const void* Data, SI32 ErrCode,
const char* ErrMessage,
SI32 ErrType)
printf("%s\n", ErrMessage);
return 0; // We try to continue
int main(int argc, char* argv[])
SI32 oc1, oc2, bmkDE, bmkEN, act, retval = -2;
PPDF* pdf = pdfNewPDF();
if (!pdf) return -1; // Out of memory?
// Pass warnings and errors to this error callback function
pdfSetOnErrorProc(pdf, NULL, PDFError);
pdfCreateNewPDF(pdf, NULL);
oc1 = pdfCreateOCG(pdf, "Deutsch", true, false, oiAll);
oc2 = pdfCreateOCG(pdf, "English", true, true, oiAll);
bmkDE = pdfAddBookmark(pdf, "Deutsch", -1, 1, false);
bmkEN = pdfAddBookmark(pdf, "English", -1, 1, false);
UI32 toggle[2] = {oc1, oc2};
// Simply toggle the state from On to Off or vice versa
act = pdfCreateSetOCGStateAction(pdf,NULL,0,NULL,0,toggle,2,true);
// Add the action to the bookmarks
pdfAddActionToObj(pdf, otBookmark, oeOnMouseUp, act, bmkDE);
pdfAddActionToObj(pdf, otBookmark, oeOnMouseUp, act, bmkEN);
pdfSetPageCoords(pdf, pcTopDown);

Previous topic: CreateSetOCGStateAction

Next topic: CreateSigField, How to lock an Interactive Form after signing?