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-------------------- //-------------------------------------------------------------
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.
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.
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”));