itextSharp将acrofields格式化为Number [英] itextSharp acrofields format as Number

查看:143
本文介绍了itextSharp将acrofields格式化为Number的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用c#代码中的ITextSharp。我使用acrofields来填充带有数据的表单。我刚刚学会了如何格式化百分比。接下来我需要学习如何格式化数字。

  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%); //正常工作
fields.SetField(value,1217000.000000,$ 1,217,000); //丢弃美元符号和逗号

我做错了什么?

解决方案

请查看),美元符号和那些逗号就在那里。



然而,当你点击其中一个字段时,iText创建的外观消失了,它被Adobe Reader创建的外观所取代(或者任何其他PDF查看器)基于字段的值(字段字典的 / V 条目):1.0或1217000.000000。这是预期的行为。



我没有声称您的指控是错误的,但是您的表单中可能有一些JavaScript将焦点设置为您的字段。也许有一个开放动作执行一些格式化字段的JavaScript。也许其他东西在起作用,但无论如何:你描述的现象的原因被埋在你的形式的某个地方。这不是由iText引起的问题:我的例子证明了问题的答案 itextpdf acrofields format as百分比也适用于货币值。


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?

解决方案

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.

这篇关于itextSharp将acrofields格式化为Number的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆