Xojo Conferences
MBSOct2019CologneDE

DynaPDF Manual - Page 428

Previous Page 427   Index   Next Page 429

Function Reference
Page 428 of 766
GetOCUINode
Syntax:
IOCN* pdfGetOCUINode(
const PPDF* IPDF,
// Instance pointer
const IOCN* Node,
// Node pointer or NULL to get the root
struct TPDFOCUINode* OutNode) // See below
struct TPDFOCUINode
{
UI32 StructSize;
// Must be set to sizeof(TOCUINode)
const char* LabelA; // Optional label.
const UI16* LabelW; // Either the Ansi or Unicode string is set at time but never both.
UI32 LabelLength;
// Length in characters without the null-terminator.
IOCN* NextChild;
// If set, the next child node that must be loaded.
LBOOL NewNode;
// If true, a new child node must be created.
SI32 OCG;
// Optional OCG handle. -1 if not set -> GetOCG().
};
The function retrieves the most important properties of an Optional Content UI node (UI stands for
User Interface).
Notice:
If the PDF file was not already imported with ImportPDFFile() the function
ImportOCProperties() must be called to import the global Optional Content Properties.
UI nodes are part of a layer configuration. Therefore, a layer configuration must be loaded with
LoadLayerConfig() before the function can be called.
Optional Content Groups (OCGs) which are returned by this function should be visible in the user
interface of a viewer application. All other OCGs should not be shown by default.
UI nodes are stored in a single linked list. To get the pointer of the root node set the parameter Node
to NULL. The parameter OutNode will be ignored in this case but it is required otherwise.
The next node of the root is the return value of this function. If no further node is available the return
value will be NULL.
Every node can contain one or more child nodes, an optional label, or a reference to an OCG.
To achieve the same nesting as in Adobe's Acrobat or Reader the nodes must be added to a custom
tree control as shown in the following simplified algorithm (Delphi):
function GetString(const ValueA: PAnsiChar; const ValueW: PWideChar): String;
begin
// Make never a direct typecast from PAnsiChar to String because this causes a buffer overrun!
if ValueA <> nil then
Result := String(AnsiString(ValueA))
else
Result := String(WideString(ValueW));
end;
// This algorithm is a bit simplified. In a real world application we must store the OCG handles in
// the tree node so that the layer state can be changed. The Delphi tree control supports the user
// defined pointer Data which can be used for this purpose. However, Data is a pointer and therefore
// we must store the OCG handles in a list before we can set the pointer. In addition, a standard tree
// control does not support the features we need to show or hide layers.
// We assume that the PDF file was already opened.
procedure TForm1.LoadLayerTreeNodes(Parent: TTreeNode; Next: IOCN; Level: Integer);
var node: TOCUINode; ocg: TPDFOCG; lbl: String; prnt, saved: TTreeNode;
 

Previous topic: GetOCHandle

Next topic: GetOutputIntent