GdPicture.NET.14
GdPicture14 Namespace / GdPicturePDF Class / DeleteOCG Method / DeleteOCG(Int32,Boolean) Method
The unique identifier of the required OCG entry that you want to delete. You can obtain this identifier using the GetOCG method.
Set this parameter to true if you want to remove all content of the layer from the document.
Example





In This Topic
DeleteOCG(Int32,Boolean) Method
In This Topic
Deletes an optional content group (OCG) entry, specified by its unique identifier, from the currently loaded PDF document. This method removes the specified OCG entry in the OCG entries dictionary and optionally removes the content of this layer from the document itself.
Syntax
'Declaration
 
Public Overloads Function DeleteOCG( _
   ByVal OCGId As Integer, _
   ByVal RemoveContent As Boolean _
) As GdPictureStatus
public GdPictureStatus DeleteOCG( 
   int OCGId,
   bool RemoveContent
)
public function DeleteOCG( 
    OCGId: Integer;
    RemoveContent: Boolean
): GdPictureStatus; 
public function DeleteOCG( 
   OCGId : int,
   RemoveContent : boolean
) : GdPictureStatus;
public: GdPictureStatus DeleteOCG( 
   int OCGId,
   bool RemoveContent
) 
public:
GdPictureStatus DeleteOCG( 
   int OCGId,
   bool RemoveContent
) 

Parameters

OCGId
The unique identifier of the required OCG entry that you want to delete. You can obtain this identifier using the GetOCG method.
RemoveContent
Set this parameter to true if you want to remove all content of the layer from the document.

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.

If the RemoveContent parameter is set to false, this method only deletes the specified OCG entry in the OCGs dictionary, which means, that the content itself of the specified layer is not removed and stay visible within the document.

Example
How to delete the specified OCG entry and its content in the PDF document.
Dim caption As String = "Example: DeleteOCG"
Dim gdpicturePDF As New GdPicturePDF()
'Please see the example of the SetImageOptional() method for the test_ImageLayer.pdf file.
If gdpicturePDF.LoadFromFile("test_ImageLayer.pdf", False) = GdPictureStatus.OK Then
    Dim ocgCount As Integer = gdpicturePDF.GetOCGCount()
    If (gdpicturePDF.GetStat() = GdPictureStatus.OK) AndAlso (ocgCount > 0) Then
        Dim ocgID As Integer = gdpicturePDF.GetOCG(0)
        If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
            If gdpicturePDF.DeleteOCG(ocgID, True) = GdPictureStatus.OK Then
                If gdpicturePDF.SaveToFile("test_DeletedLayer.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: " + gdpicturePDF.GetStat().ToString(), caption)
                End If
            Else
                MessageBox.Show("The DeleteOCG() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption)
            End If
        Else
            MessageBox.Show("The GetOCG() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption)
        End If
    Else
        MessageBox.Show("The GetOCGCount() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption)
    End If
Else
    MessageBox.Show("The file can't be loaded.", caption)
End If
gdpicturePDF.Dispose()
string caption = "Example: DeleteOCG";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
//Please see the example of the SetImageOptional() method for the test_ImageLayer.pdf file.
if (gdpicturePDF.LoadFromFile("test_ImageLayer.pdf", false) == GdPictureStatus.OK)
{
    int ocgCount = gdpicturePDF.GetOCGCount();
    if ((gdpicturePDF.GetStat() == GdPictureStatus.OK) && (ocgCount > 0))
    {
        int ocgID = gdpicturePDF.GetOCG(0);
        if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
        {
            if (gdpicturePDF.DeleteOCG(ocgID, true) == GdPictureStatus.OK)
            {
                if (gdpicturePDF.SaveToFile("test_DeletedLayer.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: " + gdpicturePDF.GetStat().ToString(), caption);
                }
            }
            else
            {
                MessageBox.Show("The DeleteOCG() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption);
            }
        }
        else
        {
            MessageBox.Show("The GetOCG() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption);
        }
    }
    else
    {
        MessageBox.Show("The GetOCGCount() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption);
    }
}
else
{
    MessageBox.Show("The file can't be loaded.", caption);
}
gdpicturePDF.Dispose();
See Also