We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Executing embedded javascript

Hello there,


I’m currently refactoring a server product that autofill’s an manipulates PDF forms (they are Government submission forms). We currently use Acrobat SDK controlled from a C# program, I am trying to convert to Aspose. I have run into a snag, Acrobat allows me to execute a JavaScript function at will like this:
_formFields.ExecuteThisJavascript(javascriptFunction);


I have not found a way of directly executing an embedded script.







Thank you for your help in advance




_________________________________________


Kenneth Lind


Information Technology Department






FNF Canada


55 Superior Boulevard I Mississauga, ON L5T 2X9


Office: 289-562-0088 | Toll-free: 877-526-3232 x 24619


Fax: 289-562-2494 | Toll-free: 888-816-2247


Email: klind@fnf.ca




www.fnf.ca

Hi Kenneth,

Thanks for your interest in our API’s.

Currently Aspose.Pdf for .NET offers the feature to add and remove JavaScript from PDF file and these scripts can be executed upon certain event i.e. Opening PDF document, printing the PDF file etc.

Following code snippet can be used to add JavaScript to PDF file but I am afraid you cannot use our API to execute the JavaScript already embedded inside PDF file when accessing it. For more information, please visit

[C#]

Document pdfDocument11 = new Document(myDir + “Annotationimport.pdf”);

string bScript = "var today = new Date(); var monthNames = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' ]; for (var p = 0; p < this.numPages; p++) { var f = this.addField('prPrintDate', 'text', p, [38, 60, 571, 0]); f.value = 'Printed Document only Effective on: ' + monthNames[today.getMonth()] + ' ' + today.getDate() + ', ' + today.getFullYear(); f.textSize = 11;f.readonly = true;f.textFont = font.HelvB;f.alignment = 'center';f.display = display.noView; }";

pdfDocument11.Actions.BeforePrinting = new JavascriptAction(bScript);

string aScript = "this.removeField('prPrintDate');";

pdfDocument11.Actions.AfterPrinting = new JavascriptAction(aScript);

pdfDocument11.Save(myDir + "Annotationimport_print.pdf");

pdfDocument11.Dispose();