GdPicture.NET.14.API
GdPicture14 Namespace / GdPicturePDF Class / BeginOCGMarkedContent Method
The unique identifier of the required OCG entry, that you want to associate the marked-content with. You can obtain this identifier using the GdPicturePDF.GetOCG method.
Example





In This Topic
BeginOCGMarkedContent Method (GdPicturePDF)
In This Topic
Begins a marked content sequence of operations associated to an optional content group specified by its unique identifier.
Syntax
'Declaration
 
Public Function BeginOCGMarkedContent( _
   ByVal OCGId As Integer _
) As GdPictureStatus
public GdPictureStatus BeginOCGMarkedContent( 
   int OCGId
)
public function BeginOCGMarkedContent( 
    OCGId: Integer
): GdPictureStatus; 
public function BeginOCGMarkedContent( 
   OCGId : int
) : GdPictureStatus;
public: GdPictureStatus BeginOCGMarkedContent( 
   int OCGId
) 
public:
GdPictureStatus BeginOCGMarkedContent( 
   int OCGId
) 

Parameters

OCGId
The unique identifier of the required OCG entry, that you want to associate the marked-content with. You can obtain this identifier using the GdPicturePDF.GetOCG method.

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 associate a graphical marked content with an optional content group.
Dim caption As String = "Example: BeginOCGMarkedContent"
Dim gdpicturePDF As New GdPicturePDF()
If (gdpicturePDF.NewPDF() = GdPictureStatus.OK) AndAlso
   (gdpicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4) = GdPictureStatus.OK) Then
    Dim ocgID As Integer = gdpicturePDF.NewOCG("Marked Content Layer")
    If gdpicturePDF.GetStat() = GdPictureStatus.OK Then
        gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitMillimeter)
        gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft)
        Dim fontName As String = gdpicturePDF.AddStandardFont(PdfStandardFont.PdfStandardFontTimesBold)
        If (gdpicturePDF.GetStat() = GdPictureStatus.OK) AndAlso
           (gdpicturePDF.SetLineColor(0, 0, 255) = GdPictureStatus.OK) AndAlso
           (gdpicturePDF.SetLineWidth(2) = GdPictureStatus.OK) AndAlso
           (gdpicturePDF.SetTextSize(30) = GdPictureStatus.OK) AndAlso
           (gdpicturePDF.SetFillColor(138, 43, 226) = GdPictureStatus.OK) AndAlso
           (gdpicturePDF.BeginOCGMarkedContent(ocgID) = GdPictureStatus.OK) AndAlso
           (gdpicturePDF.DrawRoundedRectangle(20, 20, 100, 50, 5, False, True) = GdPictureStatus.OK) AndAlso
           (gdpicturePDF.DrawTextBox(fontName, 20, 20, 120, 72, TextAlignment.TextAlignmentCenter, TextAlignment.TextAlignmentCenter, "GdPicture.NET", True) = GdPictureStatus.OK) AndAlso
           (gdpicturePDF.EndOCGMarkedContent() = GdPictureStatus.OK) Then
            If gdpicturePDF.SaveToFile("test_MarkedContentLayer.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("Error occurred when creating the marked content. Status: " + gdpicturePDF.GetStat().ToString(), caption)
        End If
    Else
        MessageBox.Show("The NewOCG() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption)
    End If
Else
    MessageBox.Show("The document can't be created.", caption)
End If
gdpicturePDF.Dispose()
string caption = "Example: BeginOCGMarkedContent";
GdPicturePDF gdpicturePDF = new GdPicturePDF();
if ((gdpicturePDF.NewPDF() == GdPictureStatus.OK) &&
    (gdpicturePDF.NewPage(PdfPageSizes.PdfPageSizeA4) == GdPictureStatus.OK))
{
    int ocgID = gdpicturePDF.NewOCG("Marked Content Layer");
    if (gdpicturePDF.GetStat() == GdPictureStatus.OK)
    {
        gdpicturePDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitMillimeter);
        gdpicturePDF.SetOrigin(PdfOrigin.PdfOriginTopLeft);
        string fontName = gdpicturePDF.AddStandardFont(PdfStandardFont.PdfStandardFontTimesBold);
        if ((gdpicturePDF.GetStat() == GdPictureStatus.OK) &&
            (gdpicturePDF.SetLineColor(0, 0, 255) == GdPictureStatus.OK) &&
            (gdpicturePDF.SetLineWidth(2) == GdPictureStatus.OK) &&
            (gdpicturePDF.SetTextSize(30) == GdPictureStatus.OK) &&
            (gdpicturePDF.SetFillColor(138, 43, 226) == GdPictureStatus.OK) &&
            (gdpicturePDF.BeginOCGMarkedContent(ocgID) == GdPictureStatus.OK) &&
            (gdpicturePDF.DrawRoundedRectangle(20, 20, 100, 50, 5, false, true) == GdPictureStatus.OK) &&
            (gdpicturePDF.DrawTextBox(fontName, 20, 20, 120, 72, TextAlignment.TextAlignmentCenter, TextAlignment.TextAlignmentCenter, "GdPicture.NET", true) == GdPictureStatus.OK) &&
            (gdpicturePDF.EndOCGMarkedContent() == GdPictureStatus.OK))
        {
            if (gdpicturePDF.SaveToFile("test_MarkedContentLayer.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("Error occurred when creating the marked content. Status: " + gdpicturePDF.GetStat().ToString(), caption);
        }
    }
    else
    {
        MessageBox.Show("The NewOCG() method has failed with the status: " + gdpicturePDF.GetStat().ToString(), caption);
    }
}
else
{
    MessageBox.Show("The document can't be created.", caption);
}
gdpicturePDF.Dispose();
See Also