Reference Guide
GdPicture14 Namespace / GdPicturePDF Class / SetOCGLockedState Method
The unique identifier of the required OCG entry. You can obtain this identifier using the GetOCG method.
The new value of the Locked state setting to be used for the specified optional content group.
Example





In This Topic
    SetOCGLockedState Method (GdPicturePDF)
    In This Topic
    Sets up the value of the Locked state setting of an optional content group specified by its unique identifier.

    The Locked state indicates, if this group is for information only. Producers can use this state to prevent the visibility of this group from being changed by users.

    Syntax
    'Declaration
     
    
    Public Function SetOCGLockedState( _
       ByVal OCGId As Integer, _
       ByVal Locked As Boolean _
    ) As GdPictureStatus
    public GdPictureStatus SetOCGLockedState( 
       int OCGId,
       bool Locked
    )
    public function SetOCGLockedState( 
        OCGId: Integer;
        Locked: Boolean
    ): GdPictureStatus; 
    public function SetOCGLockedState( 
       OCGId : int,
       Locked : boolean
    ) : GdPictureStatus;
    public: GdPictureStatus SetOCGLockedState( 
       int OCGId,
       bool Locked
    ) 
    public:
    GdPictureStatus SetOCGLockedState( 
       int OCGId,
       bool Locked
    ) 

    Parameters

    OCGId
    The unique identifier of the required OCG entry. You can obtain this identifier using the GetOCG method.
    Locked
    The new value of the Locked state setting to be used for the specified optional content group.

    Return Value

    A member of the GdPictureStatus enumeration. If the method has been successfully followed, then the return value is GdPictureStatus.OK.

    We strongly recommend always checking this status first.

    Remarks
    This method is only allowed for use with non-encrypted documents.
    Example
    How to enable the Locked state setting for the specified layer in the PDF document.
    Dim caption As String = "Example: SetOCGLockedState"
    Dim oGdPicturePDF As New GdPicturePDF()
    If (oGdPicturePDF.NewPDF() = GdPictureStatus.OK) AndAlso
       (oGdPicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4) = GdPictureStatus.OK) Then
        Dim image_res_name As String = oGdPicturePDF.AddJpegImageFromFile("image.jpg")
        Dim status As GdPictureStatus = oGdPicturePDF.GetStat()
        If status = GdPictureStatus.OK Then
            Dim ocgID As Integer = oGdPicturePDF.NewOCG("Image layer")
            status = oGdPicturePDF.GetStat()
            If (status = GdPictureStatus.OK) AndAlso
               (oGdPicturePDF.SetImageOptional(image_res_name, ocgID) = GdPictureStatus.OK) Then
                If (oGdPicturePDF.SetOCGExportState(ocgID, PdfOcgState.StateOff) = GdPictureStatus.OK) AndAlso
                   (oGdPicturePDF.SetOCGLockedState(ocgID, True) = GdPictureStatus.OK) AndAlso
                   (oGdPicturePDF.SetOCGPrintState(ocgID, PdfOcgState.StateOn) = GdPictureStatus.OK) AndAlso
                   (oGdPicturePDF.SetOCGViewState(ocgID, PdfOcgState.StateOn) = GdPictureStatus.OK) Then
                    If oGdPicturePDF.SaveToFile("test_ImageLayer.pdf") = GdPictureStatus.OK Then
                        MessageBox.Show("The example HAS been followed successfully and the file has been saved.", caption)
                    Else
                        MessageBox.Show("The example HAS been followed successfully, but the file can't be saved. Status: " + oGdPicturePDF.GetStat().ToString(), caption)
                    End If
                Else
                    MessageBox.Show("Setting up layer's options has failed with the status: " + oGdPicturePDF.GetStat().ToString(), caption)
                End If
            Else
                MessageBox.Show("The NewOCG() or SetImageOptional() method has failed with the status: " + oGdPicturePDF.GetStat().ToString(), caption)
            End If
        Else
            MessageBox.Show("The AddJpegImageFromFile() method has failed with the status: " + status.ToString(), caption)
        End If
    Else
        MessageBox.Show("The document can't be created.", caption)
    End If
    oGdPicturePDF.Dispose()
    string caption = "Example: SetOCGLockedState";
    GdPicturePDF oGdPicturePDF = new GdPicturePDF();
    if ((oGdPicturePDF.NewPDF() == GdPictureStatus.OK) &&
        (oGdPicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4) == GdPictureStatus.OK))
    {
        string image_res_name = oGdPicturePDF.AddJpegImageFromFile("image.jpg");
        GdPictureStatus status = oGdPicturePDF.GetStat();
        if (status == GdPictureStatus.OK)
        {
            int ocgID = oGdPicturePDF.NewOCG("Image layer");
            status = oGdPicturePDF.GetStat();
            if ((status == GdPictureStatus.OK) &&
                (oGdPicturePDF.SetImageOptional(image_res_name, ocgID) == GdPictureStatus.OK))
            {
                if ((oGdPicturePDF.SetOCGExportState(ocgID, PdfOcgState.StateOff) == GdPictureStatus.OK) &&
                    (oGdPicturePDF.SetOCGLockedState(ocgID, true) == GdPictureStatus.OK) &&
                    (oGdPicturePDF.SetOCGPrintState(ocgID, PdfOcgState.StateOn) == GdPictureStatus.OK) &&
                    (oGdPicturePDF.SetOCGViewState(ocgID, PdfOcgState.StateOn) == GdPictureStatus.OK))
                {
                    if (oGdPicturePDF.SaveToFile("test_ImageLayer.pdf") == GdPictureStatus.OK)
                    {
                        MessageBox.Show("The example HAS been followed successfully and the file has been saved.", caption);
                    }
                    else
                    {
                        MessageBox.Show("The example HAS been followed successfully, but the file can't be saved. Status: " + oGdPicturePDF.GetStat().ToString(), caption);
                    }
                }
                else
                {
                    MessageBox.Show("Setting up layer's options has failed with the status: " + oGdPicturePDF.GetStat().ToString(), caption);
                }
            }
            else
            {
                MessageBox.Show("The NewOCG() or SetImageOptional() method has failed with the status: " + oGdPicturePDF.GetStat().ToString(), caption);
            }
        }
        else
        {
            MessageBox.Show("The AddJpegImageFromFile() method has failed with the status: " + status.ToString(), caption);
        }
    }
    else
    {
        MessageBox.Show("The document can't be created.", caption);
    }
    oGdPicturePDF.Dispose();
    See Also