Currency formatting is lost in text Form Field while setting the value

Actual query is on stackoverflow.com. Link: http://stackoverflow.com/questions/17557444/how-to-maintain-or-force-currency-formatting-in-pdf-with-aspose

Environment: Aspose.Pdf for .NET 8.2.0 and .NET framework 4.5.

See this PDF form and open in Adobe Reader. Enter any numeric value in currency textbox e.g. 123456. It is formatted like $1,234.56. Actual value is numeric, formatting is only for the display.

When I fill this form using Aspose.Pdf, the formatting is lost. See this form, which is created by Aspose.Pdf.

Sample code:


//open document
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(dataDir + “form.pdf”);
//get a field
TextBoxField textBoxField = pdfDocument.Form[“Text2”] as TextBoxField;
//modify field value
textBoxField.Value = “123456789”;
//save updated document
pdfDocument.Save(dataDir + “form_filled.pdf”);


The issues you have found earlier (filed as PDFNEWNET-35530) have been fixed in Aspose.Pdf for .NET 8.7.0.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

Hi Saqib,


We are sorry for the delayed reponse. You may use AFNumber_Format function for field formatting. Please find a sample code snippet for the purpose. Hopefully it will help to accomplish the requirements.

Document doc = new Document("source.pdf");

TextBoxField field = doc.Form["textField"] as TextBoxField;

field.Value = "1200";

field.Actions.OnModifyCharacter = new JavascriptAction("AFNumber_Keystroke(2, 0, 1, 0, \"$\", true)");

field.Actions.OnFormat = new JavascriptAction("AFNumber_Format(2, 0, 1, 0, \"$\", true)");

doc.Save("out.pdf");

Please feel free to contact us for any further assistance.


Best Regards,