I'm using the latest Version of the community edtion of spire.pdf for .net.
I want to add calculation to the PDF. the original PDF has no JavaScript set.
maybe you can tell me what's wrong in my Code.
- Code: Select all
Spire.Pdf.PdfDocument pdf = new Spire.Pdf.PdfDocument()
Spire.Pdf.Widget.PdfFormWidget form = null;
try
{
pdf.LoadFromFile(filename);
form = pdf.Form as Spire.Pdf.Widget.PdfFormWidget;
}
catch (Exception) { }
string Formula = "this.getField(\"Field1\").value = this.getField(\"Field2\").value + 3;";
Spire.Pdf.Actions.PdfJavaScriptAction action = new Spire.Pdf.Actions.PdfJavaScriptAction(Formula);
foreach (Spire.Pdf.Fields.PdfField item in form.FieldsWidget.List)
{
if (item.Name.Equals(fieldname))
{
(item as Spire.Pdf.Widget.PdfTextBoxFieldWidget).Actions.LostFocus = action;
}
...
pdf.SaveToFile(filename);