PDF Mosaic: How to add JavaScript in PDF document


Home       Features       Download       Tutorial       Version History       License       Source Code

 

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.


 

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);
        }
    }
}

 


Home       Features       Download       Tutorial       Version History       License       Source Code