How To Add Hide Action In PDF Document Using PDF Mosiac .NET Library

This sample shows how to use Hide actions.
Using hide action (see PDFHideAction class) you can make somewidgets hidden or shown.

Hide Action

using PDFMosaic;
using System;

namespace HideAction
{
    class HideAction
    {
        static void Main()
        {
            PDFDocument document = new PDFDocument();
            PDFPage page = new PDFPage(PDFPaperFormat.A4);

            PDFEditBox editBox = new PDFEditBox(20, 40, 80, 20, "edit1");
            editBox.Text = "Text";
            page.Annotations.Add(editBox);

            PDFComboBox comboBox = new PDFComboBox(20, 70, 60, 20, "comboBox1");
            comboBox.Items.Add("Item 1");
            comboBox.Items.Add("Item 2");
            comboBox.Text = "Combo Box";
            comboBox.Font.Size = 8;
            page.Annotations.Add(comboBox);

            PDFPushButton showButton = new PDFPushButton(20, 100, 40, 15, "btn1");
            showButton.Caption = "Show";
            showButton.Font.Size = 8;
            page.Annotations.Add(showButton);

            PDFPushButton hideButton = new PDFPushButton(70, 100, 40, 15, "btn2");
            hideButton.Caption = "Hide";
            hideButton.Font.Size = 8;
            page.Annotations.Add(hideButton);

            PDFHideAction hideAction = new PDFHideAction(true);
            hideAction.Fields.Add(editBox);
            hideAction.Fields.Add(comboBox);
            hideButton.OnActivated = hideAction;

            PDFHideAction showAction = new PDFHideAction(false);
            showAction.Fields.Add(editBox);
            showAction.Fields.Add(comboBox);
            showButton.OnActivated = showAction;

            document.Pages.Add(page);
            document.Save("HideAction.pdf", true);
        }
    }
}