Hello there,
I’m trying to add a couple of form fields to a pdf document and one another to keep their product.
It’s an easy task to add fields into a document using this doc. But I’m having difficulties with adding OnCalculate action for the third field.
Here is a code that creates a new pdf document with three fields and adds OnCalculate action for the third and it looks exactly like Adobe fields, but, unfortunately, the calculation doesn’t work:
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document();
pdfDocument.Pages.Add();
Aspose.Pdf.InteractiveFeatures.Forms.TextBoxField asposeTextBoxField1, asposeTextBoxField2, asposeTextBoxFieldPRD;
Aspose.Pdf.InteractiveFeatures.Annotations.Border border;
Aspose.Pdf.InteractiveFeatures.Annotations.Dash dash = new Aspose.Pdf.InteractiveFeatures.Annotations.Dash(1, 1);
asposeTextBoxField1 = new Aspose.Pdf.InteractiveFeatures.Forms.TextBoxField(pdfDocument.Pages[1], new Aspose.Pdf.Rectangle(100, 700, 200, 750)) { PartialName = "asposeField1" };
border = new Aspose.Pdf.InteractiveFeatures.Annotations.Border(asposeTextBoxField1) { Width = 5, Dash = dash };
pdfDocument.Form.Add(asposeTextBoxField1);
asposeTextBoxField2 = new Aspose.Pdf.InteractiveFeatures.Forms.TextBoxField(pdfDocument.Pages[1], new Aspose.Pdf.Rectangle(250, 700, 350, 750)) { PartialName = "asposeField2" };
border = new Aspose.Pdf.InteractiveFeatures.Annotations.Border(asposeTextBoxField2) { Width = 5, Dash = dash };
pdfDocument.Form.Add(asposeTextBoxField2);
asposeTextBoxFieldPRD = new Aspose.Pdf.InteractiveFeatures.Forms.TextBoxField(pdfDocument.Pages[1], new Aspose.Pdf.Rectangle(400, 700, 500, 750)) { PartialName = "asposeFieldPRD" };
border = new Aspose.Pdf.InteractiveFeatures.Annotations.Border(asposeTextBoxFieldPRD) { Width = 10, Dash = dash };
asposeTextBoxFieldPRD.Actions.OnCalculate = new Aspose.Pdf.InteractiveFeatures.JavascriptAction("AFSimple_Calculate(\"PRD\", new Array (\"asposeField1\", \"asposeField2\"));");
pdfDocument.Form.Add(asposeTextBoxFieldPRD);
pdfDocument.Save("testDocument.pdf");
I would like to know, is it possible to add calculated fields using Aspose?
Taking into account attachments (image: comparing Aspose and Adobe fields, pdf doc: an example with Aspose and Adobe fields) I may suggest, I have missed something in fields creation, but I have no idea where.
Thank you in advance!
image.png (7.5 KB)
testDocument_withAdobeFields.pdf (7.9 KB)