2
我正在編寫一個需要在XFA和AcroField模板中讀取的C#應用程序。由於公司的規模以及可能與應用程序相關的現有PDF文檔的數量,選擇一個並採用它是不可能的。我如何編程讀取AcroFields和XFA字段進行填充?
我目前使用iTextSharp來讀取AcroFields,但它實際上並沒有保存更改。我使用Acrobat Pro的試用版製作了AcroFields。
編輯:(我刪了很多原始帖子)
我有一種變通方法有些工作,但對XML我寧願不做一個Deapth優先搜索。我也沒有弄清除文本字段之外的任何東西。
public List<String> getKeys(AcroFields af)
{
XfaForm xfa = af.Xfa;
List<String> Keys = new List<string>();
foreach (var field in af.Fields)
{
Keys.Add(field.Key);
}
if (xfa.XfaPresent)
{
System.Xml.XmlNode n = xfa.DatasetsNode.FirstChild;
if (n == null) return Keys;
// drill down in to the children
while (n.FirstChild != null) { n = n.FirstChild; }
// if the node is filled in data, grab the parent
if ((n.Name.ToCharArray(0, 1))[0] == '#') n = n.ParentNode;
while ((n = n.NextSibling) != null)
{
Keys.Add(n.Name);
}
}
return Keys;
}