没有表格可以在 Syncfusion PDF 上添加字段

No Form to add fields to on a Syncfusion PDF

我在我的几个程序中使用了一些 Syncfusion PDF 工具。一个程序通过 foreach 循环从 PdfLoadedDocumentForm 属性 中读取字段(并根据某些 属性 值进行一些记录保存)。这很好用。

我有另一个程序可以接收 PDF 文档,这些文档似乎并不总是有 Form 属性(doc.Form 为空)。显然,当尝试添加这样的字段时,这是一个问题:

PdfLoadedDocument PDF = new PdfLoadedDocument(@"C:\Me\Desktop\test.pdf");
PdfLoadedForm Form = PDF.Form; //Form is null
PdfLoadedPage Page = (PdfLoadedPage)PDF.Pages[0];

//Problem is, form is null for this line
PDF.Form.Fields.Add(new TextField(Page, "TEST_NAME"));

似乎没有任何方法可以 set/create 将新的 Form 添加到我在 Syncfusion 文档中可以找到的文档中。这使得该程序产生的任何内容都无法按我之前提到的程序的预期运行(没有可从中读取字段的表单)。我是不是遗漏了一些东西或者以错误的方式解决了这个问题?

当现有 PDF 文档的表单域为空时,我们必须在添加域之前创建表单。

请参考以下代码片段:

//Load the existing PDF document.
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(inputfile);

//Create the form if the form does not exist in the loaded document
if (loadedDocument.Form == null)
    loadedDocument.CreateForm();

如有任何疑问,请告诉我们。