Reference Guide
GdPicture14 Namespace / GdPicturePDF Class / GetOCG Method
The index of the required optional content group. It must be a value from 0 to GetOCGCount-1.
Example





In This Topic
    GetOCG Method (GdPicturePDF)
    In This Topic
    Returns a unique identifier of an optional content group according to the index you have specified. You can use the GetOCGCount method to determine the number of all OCG entries (layers) used in the PDF document.
    Syntax
    'Declaration
     
    
    Public Function GetOCG( _
       ByVal OCGIdx As Integer _
    ) As Integer
    public int GetOCG( 
       int OCGIdx
    )
    public function GetOCG( 
        OCGIdx: Integer
    ): Integer; 
    public function GetOCG( 
       OCGIdx : int
    ) : int;
    public: int GetOCG( 
       int OCGIdx
    ) 
    public:
    int GetOCG( 
       int OCGIdx
    ) 

    Parameters

    OCGIdx
    The index of the required optional content group. It must be a value from 0 to GetOCGCount-1.

    Return Value

    The unique identifier of the specified OCG entry. The 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 GetStat method to identify the specific reason for the method's failure, if any.

    Example
    How to find out the proper layer identifier and some of the corresponding layer's properties.
    Dim oGdPicturePDF As New GdPicturePDF()
    Dim status As GdPictureStatus = oGdPicturePDF.LoadFromFile("test.pdf", False)
    If status = GdPictureStatus.OK Then
        Dim output As String = ""
        Dim ocgCount As Integer = oGdPicturePDF.GetOCGCount()
        status = oGdPicturePDF.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 = oGdPicturePDF.GetOCG(i)
                status = oGdPicturePDF.GetStat()
                If status = GdPictureStatus.OK Then
                    title = oGdPicturePDF.GetOCGTitle(OcgId)
                    status = oGdPicturePDF.GetStat()
                    If status = GdPictureStatus.OK Then
                        output = output + "Title = " + title.ToString()
                    Else
                        output = output + "Title = Error (" + status.ToString() + ")"
                    End If
                
                    state = oGdPicturePDF.GetOCGViewState(OcgId)
                    status = oGdPicturePDF.GetStat()
                    If status = GdPictureStatus.OK Then
                        output = output + " ; View = " + state.ToString()
                    Else
                        output = output + " ; View = Error (" + status.ToString() + ")"
                    End If
                
                    state = oGdPicturePDF.GetOCGExportState(OcgId)
                    status = oGdPicturePDF.GetStat()
                    If status = GdPictureStatus.OK Then
                        output = output + " ; Export = " + state.ToString()
                    Else
                        output = output + " ; Export = Error (" + status.ToString() + ")"
                    End If
                
                    state = oGdPicturePDF.GetOCGPrintState(OcgId)
                    status = oGdPicturePDF.GetStat()
                    If status = GdPictureStatus.OK Then
                        output = output + " ; Print = " + state.ToString()
                    Else
                        output = output + " ; Print = Error (" + status.ToString() + ")"
                    End If
                
                    onOff = oGdPicturePDF.GetOCGLockedState(OcgId)
                    status = oGdPicturePDF.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: GetOCG")
        Else
            MessageBox.Show("The GetOCGCount() method has failed with the status: " + status.ToString(), "Example: GetOCG")
        End If
    Else
        MessageBox.Show("The file can't be loaded.", "Example: GetOCG")
    End If
    oGdPicturePDF.Dispose()
    GdPicturePDF oGdPicturePDF = new GdPicturePDF();
    GdPictureStatus status = oGdPicturePDF.LoadFromFile("test.pdf", false);
    if (status == GdPictureStatus.OK)
    {
        string output = "";
        int ocgCount = oGdPicturePDF.GetOCGCount();
        status = oGdPicturePDF.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 = oGdPicturePDF.GetOCG(i);
                status = oGdPicturePDF.GetStat();
                if (status == GdPictureStatus.OK)
                {
                    title = oGdPicturePDF.GetOCGTitle(OcgId);
                    status = oGdPicturePDF.GetStat();
                    if (status == GdPictureStatus.OK)
                        output = output + "Title = " + title.ToString();
                    else
                        output = output + "Title = Error (" + status.ToString() + ")";
                
                    state = oGdPicturePDF.GetOCGViewState(OcgId);
                    status = oGdPicturePDF.GetStat();
                    if (status == GdPictureStatus.OK)
                        output = output + " ; View = " + state.ToString();
                    else
                        output = output + " ; View = Error (" + status.ToString() + ")";
                
                    state = oGdPicturePDF.GetOCGExportState(OcgId);
                    status = oGdPicturePDF.GetStat();
                    if (status == GdPictureStatus.OK)
                        output = output + " ; Export = " + state.ToString();
                    else
                        output = output + " ; Export = Error (" + status.ToString() + ")";
                
                    state = oGdPicturePDF.GetOCGPrintState(OcgId);
                    status = oGdPicturePDF.GetStat();
                    if (status == GdPictureStatus.OK)
                        output = output + " ; Print = " + state.ToString();
                    else
                        output = output + " ; Print = Error (" + status.ToString() + ")";
                
                    onOff = oGdPicturePDF.GetOCGLockedState(OcgId);
                    status = oGdPicturePDF.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: GetOCG");
        }
        else
        {
            MessageBox.Show("The GetOCGCount() method has failed with the status: " + status.ToString(), "Example: GetOCG");
        }
    }
    else
    {
        MessageBox.Show("The file can't be loaded.", "Example: GetOCG");
    }
    oGdPicturePDF.Dispose();
    See Also