[英]iTextSharp doesn't work after update
After updating iTextSharp with NuGet the PDF generation stopped working. 用NuGet更新iTextSharp后,PDF生成停止工作。
i updated from 4.1.2.0 to 5.5.4.0 我从4.1.2.0更新到5.5.4.0
My original code was 我原来的代码是
using (var stream = new MemoryStream())
{
var reader = new PdfReader(pdfPath);
var stp = new PdfStamper(reader, stream);
var writer = stp.Writer;
var fieldsManager = stp.AcroFields;
foreach (DictionaryEntry entry in fieldsManager.Fields)
{
var strEntry = entry.Key.ToString();
if (strEntry == "txtNoServicio") fieldsManager.SetField(strEntry, orden.NoServicio.ToString(CultureInfo.InvariantCulture));
if (strEntry == "txtFechaCreacionTicket") fieldsManager.SetField(strEntry, orden.FechaCreacionTicket.ToString("dd/MM/yyyy"));
if (strEntry == "txtAgenteAsignado") fieldsManager.SetField(strEntry, orden.AgenteAsignado);
...
}
stp.FormFlattening = true;
stp.Close();
reader.Close();
dataBytes = stream.GetBuffer();
}
return dataBytes;
After update I changed the foreach loop from 更新后,我将foreach循环从
foreach (DictionaryEntry entry in fieldsManager.Fields)
to 至
foreach (KeyValuePair<string, AcroFields.Item> entry in fieldsManager.Fields)
The method continues to return the PDF successfully but SetValues with SetField in PDF doesn't work. 该方法继续成功返回PDF,但是PDF中带有SetField的SetValues不起作用。
Any ideas? 有任何想法吗?
Debugging I see fieldsManager.Fields
contain a property called Values and it contains a property called IsReadOnly
which is set to True
. 调试我看到fieldsManager.Fields
包含一个名为Values的属性,并且包含一个名为IsReadOnly
的属性,该属性设置为True
。 Could it mean something? 可能是什么意思吗?
You have jumped from a version that was released in 2008 to a version that was released in 2014. There are 6 years between these two versions. 您已从2008年发布的版本跃升至2014年发布的版本。这两个版本之间有6年的间隔。
(Sorry, I couldn't resist creating a Game of Thrones meme ;-) ) (对不起,我无法抗拒创建《权力的游戏》模因;-))
Please provide a SSCCE that reproduces the problem. 请提供一个重现该问题的SSCCE 。 Many people are filling out forms with iTextSharp 5.5.x without experiencing any problem. 许多人在使用iTextSharp 5.5.x填写表单时没有遇到任何问题。
What happens if you add the following line: 如果添加以下行会发生什么:
form.GenerateAppearances = true;
See ITextSharp PDFTemplate FormFlattening removes filled data 请参见ITextSharp PDFTemplate FormFlattening删除填充的数据
If this fixes your problem, then your original form has a setting that prevents iTextSharp from generating the appearances. 如果这解决了您的问题,则原始表单的设置将阻止iTextSharp生成外观。 Old iTextSharp versions ignored this setting. 旧的iTextSharp版本忽略了此设置。 More recent versions respect that setting. 最新版本尊重该设置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.