【发布时间】:2017-10-02 09:20:17
【问题描述】:
我想将我的 JSON 对象转换为 XML 以在 FillXfaForm 中使用,以使用 iText 填充我的 pdf 表单。
public void PopulatePDF(String src, string jsonString, String dest)
{
PdfDocument pdf = new PdfDocument(new PdfReader(src), new PdfWriter(dest));
PdfAcroForm form = PdfAcroForm.GetAcroForm(pdf, true);
XfaForm xfa = form.GetXfaForm();
XmlDocument xmlDoc = (XmlDocument)JsonConvert.DeserializeXmlNode(jsonString, "root");
String xmlString = xmlDoc.OuterXml;
xfa.FillXfaForm(XmlReader.Create(new StringReader(xmlString)));
xfa.Write(pdf);
pdf.Close();
}
它给了我一个错误“在 itext.forms.dll 中发生了 'System.NullReferenceException' 类型的异常,但未在用户代码中处理”。它在 xfa.FillXfaForm(XmlReader.Create(new StringReader(xmlString))) 行给出错误。
JSON 字符串如下:
{ "id": 278, "clientID": 0, "Number": null "Amount": 0.0 }
生成的 XML 字符串如下:
<root><id>278</id><clientID>0</clientID><Number /><Amount>0</Amount></root>
这是表单的链接:(它有一个名为 id 的字段) https://www.dropbox.com/s/3dkb4ry5gu8m74e/TestForm.pdf?dl=0
【问题讨论】:
-
JSON 是什么样的,生成的 XML 是什么样的?
-
@MichaelKay 添加了 JSON 和 XML
-
那我不知道,对不起。
-
您好,可以附上您的表格吗?
-
@AlexeySubach 我添加了表单链接。