Adding Javascript actions PDF

[ ]

The PdfContentEditor class present underAspose.Pdf.Facades package provides the flexibility to add Javascript actions to a PDF file. You can create a link with the serial actions corresponding to execute a menu item in the PDF viewer. This class also provides the feature to create additional actions for document events.

First of all, an object is drawn in the Document, in our example a Rectangle. And set the action createJavaScriptLink to the Rectangle. After you may save your document.

  public static void AddingJavascriptActions()
            PdfContentEditor editor = new PdfContentEditor();
            editor.BindPdf(_dataDir + "sample.pdf");
            // create Javascript link
            System.Drawing.Rectangle rect = new System.Drawing.Rectangle(50, 750, 50, 50);
            String code = "app.alert('Welcome to Aspose!');";
            editor.CreateJavaScriptLink(code, rect, 1, System.Drawing.Color.Green);
            // save the output file
            editor.Save(_dataDir + "JavaScriptAdded_output.pdf");