(Read this for a refresher on the http://help.quickpdflibrary.com/questions/352/what-is-the-difference-between-layers-and-optional-content-groups-ocgs-in-quick - difference between OCGs and Layers in Quick PDF's world).
Sometimes there is a difference between the number of Optional Content Groups returned by the OptionalContentGroupCount function and the number of Optional Content Groups which are displayed in the Layers panel in Adobe Reader.
The OptionalContentGroupCount function counts all of the OCGs that are listed in the OCG array in the PDF, but there is a different dictionary in the PDF which deals with the configuration of the OCGs and whether or not specific OCGs are actually used in the conforming PDF viewer.
Most of the time the total number of OCGs found in the OCG array and the number of OCGs that the configuration dictionary directs the conforming PDF viewer to display are the same, but sometimes they are not.
This means that it is prudent to check the GetOptionalContentConfigOrderCount function to see if a configuration dictionary exists, and if one does, then to use the GetOptionalContentConfigOrderItemID, GetOptionalContentConfigOrderItemLabel, GetOptionalContentConfigOrderItemLevel, and GetOptionalContentConfigOrderItemType functions to get all of the information required to determine which OCGs are actually displayed in the Layers panel in Adobe Reader.
Here is some C# code to show you an example of how to check the configuration dictionary to see what OCGs will be shown in Adobe Reader:
QP.LoadFromFile(OpenFilePath());
int ContentConfigCount = QP.GetOptionalContentConfigCount();
txtOutput.AppendText("Total Content Config Count: " + ContentConfigCount); txtOutput.AppendText(Environment.NewLine);
int OrderCount = QP.GetOptionalContentConfigOrderCount(1);
for (int i = 1; i <= OrderCount; i++) { int OrderItemID = QP.GetOptionalContentConfigOrderItemID(1, i); string OrderItemLabel = QP.GetOptionalContentConfigOrderItemLabel(1, i); int OrderItemLevel = QP.GetOptionalContentConfigOrderItemLevel(1, i); int OrderItemType = QP.GetOptionalContentConfigOrderItemType(1, i);
txtOutput.AppendText("Order Item ID: " + OrderItemID); txtOutput.AppendText(Environment.NewLine);
txtOutput.AppendText("Order Item Label: " + OrderItemLabel); txtOutput.AppendText(Environment.NewLine);
txtOutput.AppendText("Order Item Level: " + OrderItemLevel); txtOutput.AppendText(Environment.NewLine);
txtOutput.AppendText("Order Item Type: " + OrderItemType); txtOutput.AppendText(Environment.NewLine); }
|