itextSharp acrofields format as Number

戏子无情 提交于 2019-12-11 22:29:53

问题


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?


回答1:


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:

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.



来源:https://stackoverflow.com/questions/27711035/itextsharp-acrofields-format-as-number

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!