0

I use ITextSharp from c# code. I use acrofields to populate a form with data. I am just learnt how to format percentage. Next I need to learn how to format numbers.

Stream os = new FileStream(PDFPath, FileMode.CreateNew);
PdfReader reader = new PdfReader(memIO);
PdfStamper stamper = new PdfStamper(reader, os, '9', true);
AcroFields fields = stamper.AcroFields;
fields.SetField("Pgo", "1.0",  "100%");    // Works fine
fields.SetField("value", "1217000.000000",  "$1,217,000");    // Drops Dollar sign and comma

What am I doing wrong?

Arne
  • 11
  • 4
  • possible duplicate of [itextpdf acrofields format as Percentage](http://stackoverflow.com/questions/27695621/itextpdf-acrofields-format-as-percentage) – eddie_cat Dec 30 '14 at 19:34
  • It's not really a duplicate, as it uses the answer of that previous question (see `// Works fine`). It's an extension of that original question asking about a different phenomenon: `// Drops Dollar sign and comma`. I'll answer it in the sense that the problem can not be reproduced. I'll also explain possible causes. – Bruno Lowagie Dec 31 '14 at 08:38
  • @Arne as a corollary: if you have a PDF with which your issue occurs, provide it with your question. – mkl Dec 31 '14 at 09:41

1 Answers1

0

Please take a look at the FormatFields example. In that example, I took an ordinary form with a couple of ordinary fields, and I filled these fields in the exact same way as you did.

The result looks as expected:

enter image description here

iText has created two appearances (the /AP entry of the widget annotation) based on the display parameter we passed to the setField() method. One field shows "100$", the other field shows "$1,217,000". As you can see (and check for yourself here), the dollar sign and the commas are there.

However, the moment you click one of those fields, the appearance that was created by iText disappears and it's replaced by an appearance created by Adobe Reader (or any other PDF viewer) based on the value of the field (the /V entry of the field dictionary): "1.0" or "1217000.000000". This is expected behavior.

I am not claiming that your allegation is wrong, but maybe there is some JavaScript in your form that sets the focus to your value field. Maybe there's an open action that performs some JavaScript that formats the value field. Maybe something else is at play, but in any case: the reason for the phenomenon you describe is buried somewhere in your form. It is not a problem caused by iText: my example proves that the answer to the question itextpdf acrofields format as Percentage also works for currency values.

Community
  • 1
  • 1
Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165
  • Thanks for our answer. Your example does not work for me. I will investigate. – Arne Jan 05 '15 at 12:37
  • Your example does not use Acrobat built-in formatting attributes – Arne Jan 19 '15 at 20:56
  • These are not triggered by iText as iText doesn't interpret the Javascript. As you didn't share your form, there was no way to know which of the pre-canned `AF_` functions are at play in your form. – Bruno Lowagie Jan 20 '15 at 07:49
  • 1. Created a test PDF form from scratch. The iText software now behaves well. I have long suspected there is something wrong with my legacy PDF forms. 2. your example at http://itextpdf.com/sites/default/files/field_format.pdf does not use Acrobat built-in formatting and does not capture my problem. – Arne Jan 21 '15 at 15:17