Print Page | Close Window

Tips for working with OCGs and Config Dictionaries

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: Sample Code
Forum Description: Share Debenu Quick PDF Library sample code with other forum members
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=1765
Printed Date: 22 Nov 24 at 6:24PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Tips for working with OCGs and Config Dictionaries
Posted By: Rowan
Subject: Tips for working with OCGs and Config Dictionaries
Date Posted: 10 Mar 11 at 9:15AM
(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);
}





Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk