Reference Guide
GdPicture14 Namespace / GdPicturePDF Class / EndOCGMarkedContent Method
Example





In This Topic
    EndOCGMarkedContent Method (GdPicturePDF)
    In This Topic
    Ends the marked content, that has been previously defined by using the BeginOCGMarkedContent method.
    Syntax
    'Declaration
     
    
    Public Function EndOCGMarkedContent() As GdPictureStatus
    public GdPictureStatus EndOCGMarkedContent()
    public function EndOCGMarkedContent(): GdPictureStatus; 
    public function EndOCGMarkedContent() : GdPictureStatus;
    public: GdPictureStatus EndOCGMarkedContent(); 
    public:
    GdPictureStatus EndOCGMarkedContent(); 

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