How To Add JavaScript In PDF Document Using PDF Mosaic .NET Library

This sample shows how to use JavaScript actions.
You can execute javascript code as the result of an action. UsePDFJavaScriptAction class to create a javascript action.

JavaScript Action


using PDFMosaic;
using System;

namespace JavaScriptAction
    class JavaScriptAction
        static void Main()
            PDFDocument document = new PDFDocument();
            document.Pages.Add(new PDFPage(PDFPaperFormat.A4));

            PDFJavaScriptAction onOpenAction = new PDFJavaScriptAction("app.alert(\"Hello!\",3)");
            document.OnOpenDocument = onOpenAction;

            PDFJavaScriptAction onBeforeClosing = new PDFJavaScriptAction("app.alert(\"Bye!\",3)");
            document.OnBeforeClosing = onBeforeClosing;

            document.Save("JavaScriptAction.pdf", true);