itextpdf acrofields格式为百分比 [英] itextpdf acrofields format as Percentage

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

问题描述

我使用ITextPdf feom c#代码。
我使用acrofields来填充带有数据的表单。我正在丢失格式。

I use ITextPdf feom c# code. I use acrofields to populate a form with data. I am losing my formatting.

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  "Percentage");

我做错了什么?

推荐答案

你说你丢失了所有的格式。这导致假设您的表单包含JavaScript,当用户输入值时格式化字段。

You say you are losing all your formatting. This leads to the assumption that your form contains JavaScript that formats fields when a human user enters a value.

当您使用iText填写表单时,JavaScript方法是手动填写表单时触发,不执行。因此 1.0 将不会更改为 100%

When you fill out a form using iText, the JavaScript methods that are triggered when a form is filled out manually, aren't executed. Hence 1.0 will not be changed into 100%.

我认为这是一个错字:

fields.SetField("Pgo", 1.0  "Percentage");

此行甚至无法编译。键入此行时,IDE应显示错误。即使我在第二个和第三个参数之间添加缺少的逗号(假设 1.0 百分比是两个单独的参数),你会收到一个错误,说没有 setField()方法接受 String ,一个 double 和一个 String

This line doesn't even compile. Your IDE should show an error when typing this line. Even if I would add the missing comma between the second and third parameter (assuming that 1.0 and "Percentage" are two separate parameters), you'd get an error saying that there is no setField() method that accepts a String, a double and a String.

有两个 setField()方法:

  • setField(String name, String value): the first parameter is the key (e.g. "Pgo"), the second one is the value (e.g. the String value "1.0").
  • setField(String name, String value, String display): the first parameter is the key (e.g. "Pgo"), the second one is the value (e.g. the String value "1.0"), and the third parameter is what should be displayed (e.g. "100%").

例如,当你这样做时:

fields.SetField("Pgo", "1.0", "100%");

iText将显示100%,但该字段的值将为1.0。

iText will display 100%, but the value of the field will be 1.0.

如果有人点击该字段,则可能会出现1.0,以便最终用户可以更改字段,例如更改为0.5。它将取决于格式化JavaScript的存在,无论这个手动输入的0.5是否将显示为50%。

If somebody clicks the field, 1.0 could appear, so that the end user can change the field, for instance into 0.5. It will depend on the presence of formatting JavaScript whether or not this manually entered 0.5 will be displayed as 50% or not.

PS:这个问题也被发布为pre - 我们在iText Software的售票系统中的销售问题。我正在关闭那张票,这样票不会被回答两次。顺便说一句:这个新的问题只不过是对你上一个问题的重复讨论 https://stackoverflow.com/questions/27276863/pdfstamper-remove-my-formats-in-my-form 。那个问题不清楚。你为什么忽略我澄清的要求?当您第一次没有得到答案时,发布重复的问题并不是自定义的。您应该更新原始问题。

P.S.: this question was also posted as a pre-sales question in our ticketing system at iText Software. I am closing that ticket so that the ticket won't be answered twice. By the way: this new question is nothing more than a rehash of your previous question https://stackoverflow.com/questions/27276863/pdfstamper-remove-my-formats-in-my-form. That question was unclear. Why did you ignore my request to clarify? It is not custom to post a duplicate question when you didn't get an answer the first time. You should have updated your original question.

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

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