GdPicture.NET.14.API
GdPicture14 Namespace / GdPicturePDF Class / GetOCGTitle Method
The unique identifier of the required OCG entry. You can obtain this identifier using the GdPicturePDF.GetOCG method.
Example





In This Topic
GetOCGTitle Method (GdPicturePDF)
In This Topic
Returns the title of an optional content group, in other words the name of a layer, specified by its unique identifier. This name is presented in the viewer's user interface.
Syntax
'Declaration
 
Public Function GetOCGTitle( _
   ByVal OCGId As Integer _
) As String
public string GetOCGTitle( 
   int OCGId
)
public function GetOCGTitle( 
    OCGId: Integer
): String; 
public function GetOCGTitle( 
   OCGId : int
) : String;
public: string* GetOCGTitle( 
   int OCGId
) 
public:
String^ GetOCGTitle( 
   int OCGId
) 

Parameters

OCGId
The unique identifier of the required OCG entry. You can obtain this identifier using the GdPicturePDF.GetOCG method.

Return Value

The title of the specifed optional content group. The GdPicturePDF.GetStat method can be subsequently used to determine if this method has been successful.
Remarks
This method is only allowed for use with non-encrypted documents.

It is recommend to use the GdPicturePDF.GetStat method to identify the specific reason for the method's failure, if any.

Example
How to find out the title of the specified layer and some other layer's properties.
Dim gdpicturePDF As New GdPicturePDF()
Dim status As GdPictureStatus = gdpicturePDF.LoadFromFile("test.pdf", False)
If status = GdPictureStatus.OK Then
    Dim output As String = ""
    Dim ocgCount As Integer = gdpicturePDF.GetOCGCount()
    status = gdpicturePDF.GetStat()
    If status = GdPictureStatus.OK Then
        output = "The number of OCG layers: " + ocgCount.ToString()
        Dim OcgId As Integer = 0
        Dim title As String = ""
        Dim state As PdfOcgState = PdfOcgState.Undefined
        Dim onOff As Boolean = False
        For i As Integer = 0 To ocgCount - 1
            output = output + vbCrLf + "Nr." + (i + 1).ToString() + ": "
            OcgId = gdpicturePDF.GetOCG(i)
            status = gdpicturePDF.GetStat()
            If status = GdPictureStatus.OK Then
                title = gdpicturePDF.GetOCGTitle(OcgId)
                status = gdpicturePDF.GetStat()
                If status = GdPictureStatus.OK Then
                    output = output + "Title = " + title.ToString()
                Else
                    output = output + "Title = Error (" + status.ToString() + ")"
                End If
            
                state = gdpicturePDF.GetOCGViewState(OcgId)
                status = gdpicturePDF.GetStat()
                If status = GdPictureStatus.OK Then
                    output = output + " ; View = " + state.ToString()
                Else
                    output = output + " ; View = Error (" + status.ToString() + ")"
                End If
            
                state = gdpicturePDF.GetOCGExportState(OcgId)
                status = gdpicturePDF.GetStat()
                If status = GdPictureStatus.OK Then
                    output = output + " ; Export = " + state.ToString()
                Else
                    output = output + " ; Export = Error (" + status.ToString() + ")"
                End If
            
                state = gdpicturePDF.GetOCGPrintState(OcgId)
                status = gdpicturePDF.GetStat()
                If status = GdPictureStatus.OK Then
                    output = output + " ; Print = " + state.ToString()
                Else
                    output = output + " ; Print = Error (" + status.ToString() + ")"
                End If
            
                onOff = gdpicturePDF.GetOCGLockedState(OcgId)
                status = gdpicturePDF.GetStat()
                If status = GdPictureStatus.OK Then
                    output = output + " ; Locked = " + onOff.ToString()
                Else
                    output = output + " ; Locked = Error (" + status.ToString() + ")"
                End If
            Else
                output = output + "The GetOCG() method has failed with the status: " + status.ToString()
            End If
        Next
        MessageBox.Show(output, "Example: GetOCGTitle")
    Else
        MessageBox.Show("The GetOCGCount() method has failed with the status: " + status.ToString(), "Example: GetOCGTitle")
    End If
Else
    MessageBox.Show("The file can't be loaded.", "Example: GetOCGTitle")
End If
gdpicturePDF.Dispose()
GdPicturePDF gdpicturePDF = new GdPicturePDF();
GdPictureStatus status = gdpicturePDF.LoadFromFile("test.pdf", false);
if (status == GdPictureStatus.OK)
{
    string output = "";
    int ocgCount = gdpicturePDF.GetOCGCount();
    status = gdpicturePDF.GetStat();
    if (status == GdPictureStatus.OK)
    {
        output = "The number of OCG layers: " + ocgCount.ToString();
        int OcgId = 0;
        string title = "";
        PdfOcgState state = PdfOcgState.Undefined;
        bool onOff = false;
        for (int i = 0; i < ocgCount; i++)
        {
            output = output + "\nNr." + (i + 1).ToString() + ": ";
            OcgId = gdpicturePDF.GetOCG(i);
            status = gdpicturePDF.GetStat();
            if (status == GdPictureStatus.OK)
            {
                title = gdpicturePDF.GetOCGTitle(OcgId);
                status = gdpicturePDF.GetStat();
                if (status == GdPictureStatus.OK)
                    output = output + "Title = " + title.ToString();
                else
                    output = output + "Title = Error (" + status.ToString() + ")";
            
                state = gdpicturePDF.GetOCGViewState(OcgId);
                status = gdpicturePDF.GetStat();
                if (status == GdPictureStatus.OK)
                    output = output + " ; View = " + state.ToString();
                else
                    output = output + " ; View = Error (" + status.ToString() + ")";
            
                state = gdpicturePDF.GetOCGExportState(OcgId);
                status = gdpicturePDF.GetStat();
                if (status == GdPictureStatus.OK)
                    output = output + " ; Export = " + state.ToString();
                else
                    output = output + " ; Export = Error (" + status.ToString() + ")";
            
                state = gdpicturePDF.GetOCGPrintState(OcgId);
                status = gdpicturePDF.GetStat();
                if (status == GdPictureStatus.OK)
                    output = output + " ; Print = " + state.ToString();
                else
                    output = output + " ; Print = Error (" + status.ToString() + ")";
            
                onOff = gdpicturePDF.GetOCGLockedState(OcgId);
                status = gdpicturePDF.GetStat();
                if (status == GdPictureStatus.OK)
                    output = output + " ; Locked = " + onOff.ToString();
                else
                    output = output + " ; Locked = Error (" + status.ToString() + ")";
            }
            else
                output = output + "The GetOCG() method has failed with the status: " + status.ToString();
        }
        MessageBox.Show(output, "Example: GetOCGTitle");
    }
    else
    {
        MessageBox.Show("The GetOCGCount() method has failed with the status: " + status.ToString(), "Example: GetOCGTitle");
    }
}
else
{
    MessageBox.Show("The file can't be loaded.", "Example: GetOCGTitle");
}
gdpicturePDF.Dispose();
See Also