Add Javascript to Page Action

Hello,

I require the ability to add JavaScript on a Page action.

Specifically a Page Open action.

And to be able to set custom JavaScript on particular pages.

Eg:

using

(var pdf = new Aspose.Pdf.Document(pdfFilename))

{

pdf.OpenAction =

new JavascriptAction("app.alert('Hello World!');"); // Can already do this

for (var pageNo = 1; pageNo < pdf.Pages.Length; pageNo++)

pdf.Pages[pageNo].OpenAction =

new JavascriptAction(string.Format("app.alert('Hello Page {0}');", pageNo)); // Need to do this

pdf.Save(outPath);

}

And the resulting embedded JavaScript to look like:

//-------------------------------------------------------------
//-----------------Do not edit the XML tags--------------------
//-------------------------------------------------------------

//
//init
//
/*********** belongs to: Document-Level:init ***********/
app.alert('Hello World!');
//
//

//
//Page1:Page Open:Action1
//
/*********** belongs to: Page-Actions:Page1:Page Open:Action1 ***********/
app.alert('Hello Page 1');
//
//

//
//Page2:Page Open:Action1
//
/*********** belongs to: Page-Actions:Page2:Page Open:Action1 ***********/
app.alert('Hello Page 2');
//
//

Hi Viktor,


I have gone through the code snippet and the JavaScript which you have shared but I am afraid I could not understand the issue that you are facing. Can you please share some details.

Aspose.PDF currently allows me to set JavaScript on a Document Action (e.g. Document Open in my example).

This is good. But I also need to be able to set JavaScript on a Page Action. I included an example syntax for this in my example with a comment saying "Need to do this". Currently the API does not support this (from what I can see in the documentation).

The example JavaScript is what I would expect example code to produce. The first part of the JavaScript is produced by the Document Open JavaScriptAction (this I can already do). The second two segments would be produced by the requested API call for a Page Action.

I have succeeded in acheiving this with the iText library (I can provide the code if it will help), but owuld like to do it with Aspose for which we have bought the entire .NET library.

Hi Viktor,


Sorry for the delayed response.

I am afraid the requested feature is
currently not supported but for the sake of implementation, I have logged this
requirement in our issue tracking system under New Features list as
<span style=“font-size:10.0pt;mso-bidi-font-size:12.0pt;font-family:“Arial”,“sans-serif”;
mso-fareast-font-family:SimSun;mso-fareast-language:ZH-CN”>PDFNEWNET-34589
. We will further investigate this requirement
in details and will keep you updated on the status of a correction.

We
apologize for your inconvenience.

Hi Viktor,


Thanks for your patience.

I am pleased to share that the feature request to add JavaScript against page action has been implemented. In order to accomplish this requirement, PageActionCollection is implemented. This class has properties:

  • public PdfAction OnOpen
  • public PdfAction OnClose

You may set actions for page open/close with the following code:

[C#]

Document doc = new
Document(TestSettings.GetInputFile(“PdfWithSeveralPages.pdf”));

doc.Pages[5].Actions.OnOpen = new JavascriptAction("app.alert('open')");

doc.Pages[5].Actions.OnClose = new JavascriptAction("app.alert('close')");

doc.Save(TestSettings.GetOutputFile("34589.pdf"));


PS, This new class will become available in upcoming release version of Aspose.Pdf for .NET 7.7.0.

The issues you have found earlier (filed as PDFNEWNET-34589) have been fixed in Aspose.Pdf for .NET 7.7.0.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.