GdPicture.NET.14.API
GdPicture14 Namespace / GdPicturePDF Class / SetOCGExportState Method
The unique identifier of the required OCG entry. You can obtain this identifier using the GdPicturePDF.GetOCG method.
A member of the PdfOcgState enumeration. The new value of the Export state setting to be used for the specified optional content group.
Example





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

The Export state indicates, if the content in this group is exported, when the document (or part of it) is saved by a viewer application to a format, that does not support optional content (for example, an earlier version of PDF or a raster image format).

Syntax
'Declaration
 
Public Function SetOCGExportState( _
   ByVal OCGId As Integer, _
   ByVal ExportState As PdfOcgState _
) As GdPictureStatus
public GdPictureStatus SetOCGExportState( 
   int OCGId,
   PdfOcgState ExportState
)
public function SetOCGExportState( 
    OCGId: Integer;
    ExportState: PdfOcgState
): GdPictureStatus; 
public function SetOCGExportState( 
   OCGId : int,
   ExportState : PdfOcgState
) : GdPictureStatus;
public: GdPictureStatus SetOCGExportState( 
   int OCGId,
   PdfOcgState ExportState
) 
public:
GdPictureStatus SetOCGExportState( 
   int OCGId,
   PdfOcgState ExportState
) 

Parameters

OCGId
The unique identifier of the required OCG entry. You can obtain this identifier using the GdPicturePDF.GetOCG method.
ExportState
A member of the PdfOcgState enumeration. The new value of the Export 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 disable the Export state setting for the specified layer in the PDF document.
Dim caption As String = "Example: SetOCGExportState"
Dim gdpicturePDF As New GdPicturePDF()
If (gdpicturePDF.NewPDF() = GdPictureStatus.OK) AndAlso
   (gdpicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4) = GdPictureStatus.OK) Then
    Dim image_res_name As String = gdpicturePDF.AddJpegImageFromFile("image.jpg")
    Dim status As GdPictureStatus = gdpicturePDF.GetStat()
    If status = GdPictureStatus.OK Then
        Dim ocgID As Integer = gdpicturePDF.NewOCG("Image layer")
        status = gdpicturePDF.GetStat()
        If (status = GdPictureStatus.OK) AndAlso
           (gdpicturePDF.SetImageOptional(image_res_name, ocgID) = GdPictureStatus.OK) Then
            If (gdpicturePDF.SetOCGExportState(ocgID, PdfOcgState.StateOff) = GdPictureStatus.OK) AndAlso
               (gdpicturePDF.SetOCGLockedState(ocgID, True) = GdPictureStatus.OK) AndAlso
               (gdpicturePDF.SetOCGPrintState(ocgID, PdfOcgState.StateOn) = GdPictureStatus.OK) AndAlso
               (gdpicturePDF.SetOCGViewState(ocgID, PdfOcgState.StateOn) = GdPictureStatus.OK) Then
                If gdpicturePDF.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: " + gdpicturePDF.GetStat().ToString(), caption)
                End If
            Else
                MessageBox.Show("Setting up layer's options has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption)
            End If
        Else
            MessageBox.Show("The NewOCG() or SetImageOptional() method has failed with the status: " + gdpicturePDF.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
gdpicturePDF.Dispose()
string caption = "Example: SetOCGExportState";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
if ((gdpicturePDF.NewPDF() == GdPictureStatus.OK) &&
    (gdpicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4) == GdPictureStatus.OK))
{
    string image_res_name = gdpicturePDF.AddJpegImageFromFile("image.jpg");
    GdPictureStatus status = gdpicturePDF.GetStat();
    if (status == GdPictureStatus.OK)
    {
        int ocgID = gdpicturePDF.NewOCG("Image layer");
        status = gdpicturePDF.GetStat();
        if ((status == GdPictureStatus.OK) &&
            (gdpicturePDF.SetImageOptional(image_res_name, ocgID) == GdPictureStatus.OK))
        {
            if ((gdpicturePDF.SetOCGExportState(ocgID, PdfOcgState.StateOff) == GdPictureStatus.OK) &&
                (gdpicturePDF.SetOCGLockedState(ocgID, true) == GdPictureStatus.OK) &&
                (gdpicturePDF.SetOCGPrintState(ocgID, PdfOcgState.StateOn) == GdPictureStatus.OK) &&
                (gdpicturePDF.SetOCGViewState(ocgID, PdfOcgState.StateOn) == GdPictureStatus.OK))
            {
                if (gdpicturePDF.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: " + gdpicturePDF.GetStat().ToString(), caption);
                }
            }
            else
            {
                MessageBox.Show("Setting up layer's options has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption);
            }
        }
        else
        {
            MessageBox.Show("The NewOCG() or SetImageOptional() method has failed with the status: " + gdpicturePDF.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);
}
gdpicturePDF.Dispose();
See Also