Fill in a form then apply Javascript

Hi,

I am using the Aspose .NET libraries for an evaluation.

I need to know if its possible to be able to fill in my form and then apply some Javascript to the document. I tried the code below but it did not work:

var directory = Directory.GetCurrentDirectory();
formFile =
String.Format("{0}\\Employment Application.pdf", directory);
newFile =
String.Format("{0}\\Employment Application - {1} {2}.pdf", directory, firstName, lastName);

using (Document doc = new Document(formFile))
{
TextBoxField firstNameField = doc.Form["FirstName"] as TextBoxField;
TextBoxField lastNameField = doc.Form["LastName"] as TextBoxField;

firstNameField.Value = firstName;
lastNameField.Value = lastName;

doc.Save(newFile);
}

using (FileStream fs = new FileStream(newFile, FileMode.OpenOrCreate))
{
Pdf pdf = new Pdf(fs);

pdf.JavaScripts = new JavaScripts();
pdf.JavaScripts.Add(new JavaScript
{
ID = "Alert",
ScriptContent = String.Format("app.alert(\"Hi {0} {1}\");", firstName, lastName)
});
pdf.JavaScripts.Add(new JavaScript
{
ID = "Print",
ScriptContent = "this.print(true);"
});

pdf.Save(fs);
}

EDIT:
I should mention that the code does fill in the first and last names correctly, it just wont apply the Javascript to the document. The main issue I'm actually having is that the are no exceptions coming back when saving the file with Javascript on it.

Thanks,

Macklin.

Hi Macklin,

Thanks for your inquiry. Yes you can easily add Javascript to Document, Page or field level. Please check following documentation links for the details. Hopefully it will help you to accomplish the task.

Please feel free to contact us for any further assistance.

Best Regards,

Hi


That appears to have done the trick. I had not seen those particular pages of the documentation before.

Thanks,

Macklin

Hi Macklin,


Thanks for your feedback. It is good to know that you have managed to accomplish the task.

Please keep using our API and feel free to ask any question or concern. We will more than happy to extend our support.

Best Regards,