Adding Javascript actions to a PDF file
PdfContentEditor provides you 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. You can also create a Javascript link using this class. In addition to that, you can create additional actions for document events.
The following sample code shows you how to add Javascript actions in a PDF file.
PdfContentEditor provides you 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. You can also create a Javascript link using this class. In addition to that, you can create additional actions for document events.
The following sample code shows you how to add Javascript actions in a PDF file.
[Java]
//create PdfContentEditor object to manipulate contents PdfContentEditor editor = new PdfContentEditor(); editor.bindPdf("input.pdf"); //create a Link with a serial actions corresponding to execute a menu item in Acrobat viewer. Rectangle rect6 = new Rectangle(50, 50, 200, 200); Color clr3 = new Color(0, 255, 0); String[] actionName ={ MenuActionName.DOCUMENT_ATTACHFILE, MenuActionName.DOCUMENT_EXTRACTPAGES }; editor.createCustomActionLink(rect6, 1, clr3, actionName); //create Javascript link Rectangle rect7 = new Rectangle(50, 50, 200, 200); Color clr4 = new Color(0, 255, 0); String code = "app.alert('welcome to aspose!');"; editor.createJavaScriptLink(code, rect7, 1, clr4); //create additional actions for document events editor.addDocumentAdditianalAction(PdfContentEditor.DOCUMENT_OPEN, "app.alert('Welcome to read this document.');"); editor.addDocumentAdditianalAction(PdfContentEditor.DOCUMENT_CLOSE, "app.alert('Welcome to read this document.');"); //save the output file editor.save("output.pdf");
