I'm sure that I'm missing something very simple, but I am bewildered as to why I can save the PDF with or without form flattening completely as expected, yet the Forms.Fields.List.Count returns 0
//save example to C drive (taken from adobe website)
- Code: Select all
using System;
using System.Collections.Generic;
using Spire.Pdf;
using Spire.Pdf.Widget;
namespace spireTest
{
class Program
{
static void Main(string[] args)
{
string formPath = @"E:\create-forms-sample.pdf";
Dictionary<string, string> dict = new Dictionary<string, string>();
FillPDFForm(formPath, dict);
Console.ReadLine();
}
public static PdfDocument FillPDFForm(string sourcePDF,
Dictionary<string, string> formResults)
{
PdfDocument doc = new PdfDocument();
doc.LoadFromFile(sourcePDF);
PdfFormWidget formWidget = doc.Form as PdfFormWidget;
Console.WriteLine("Form widget has length {0}",formWidget.Fields.Count);
Console.WriteLine("Form has length {0}", doc.Form.Fields.List.Count);
for (int i = 0; i < formWidget.FieldsWidget.List.Count; i++)
{
//can't fill forms if widget field list is empty!
}
//doc.Form.IsFlatten = true;
//doc.SaveToFile(@"C:\canFlattenAndSave.pdf"); //can flatten ok.
return doc;
}
}
}