Adding Javascript actions to existing PDF file
Contents
[
Hide
]
The PdfContentEditor class present under com.aspose.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
java.awt.Rectangle rect = new java.awt.Rectangle(50, 750, 50, 50);
String code = "app.alert('Welcome to Aspose!');";
editor.createJavaScriptLink(code, rect, 1, java.awt.Color.GREEN);
// save the output file
editor.save(_dataDir+"JavaScriptAdded_output.pdf");
}