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

Free Support Forum - aspose.com

Negative values get wrong format in PDF forms

We are using Aspose PDF library to merge data from one of our cloud systems to some PDF templates, using .NET.
The aspose pdf form class and aspose pdf field only handles string values, so we need to convert amounts to strings to merge the data with the PDF template fields.
image.png (2.3 KB)

The problem is that the PDF template use a format for amounts:
image.png (4.0 KB)

and when it interpret the values merged as strings, it is not handling well a “-” sign.

image.png (6.8 KB)

Is there a way to fix this format bug?

@alebermudez

Would you please share some sample source file(s) and code snippet with us to replicate the issue in our environment. We will test the scenario and address it accordingly.

foreach (Field asposeField in asposeDoc.Form.Fields)
//foreach (Field asposeField in form.Document.Form.Fields)
{
// get the name
var fieldName = asposeField.FullName;

                // find the value from the pdfDocument model -- string values
                var value = pdfDoc.Fields.Where(f => f.FieldName == fieldName).FirstOrDefault();

                // map the value to the field
                if (value != null && !string.IsNullOrEmpty(value.FieldValue))
                {
                    asposeField.Value = value.FieldValue;

                    // TODO: lock the field here
                    if (fieldName.Equals("guid") || fieldName.Equals("base_url"))
                    {
                        continue;
                    }
                    asposeField.Flatten();

                    logger.WriteVerbose("PdfController.BuildDoc mapping field: " + fieldName + " to the aspose field value: " + value.FieldValue);
                }
                else
                {
                    logger.WriteVerbose("PdfController.BuildDoc mapping field: " + fieldName + " did not have a value pulled from aspose fields list.");
                }
            }

Customer Proposal Letter - RTC Mockup (v9).pdf (2.8 MB)

@alebermudez

We noticed that you are reading field names and values from another class in your code snippet. However, you may please only share a field name where you want to populate the value with “-” sign. We will try to set it at our side and share our feedback with you.

You can try something like this:

            foreach (Field asposeField in asposeDoc.Form.Fields)
            //foreach (Field asposeField in form.Document.Form.Fields)
            {
                // get the name
                var fieldName = asposeField.FullName;

                if (fieldName = "DepositDownPayment"|| fieldName = "Rebate1")
                {
                    asposeField.Value = "-800.00";
                }
                    asposeField.Flatten();
            }

@alebermudez

We were able to reproduce the issue in our environment while using Aspose.PDF for .NET 20.8 and logged it as PDFNET-48695 in our issue tracking system. We will further look into its details and keep you posted with the status of its correction. Please be patient and spare us some time.

We are sorry for the inconvenience.

1 Like