代码之家  ›  专栏  ›  技术社区  ›  Broots Waymb

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

  •  1
  • Broots Waymb  · 技术社区  · 9 年前

    我在几个程序中使用了一些Syncfusion PDF工具。一个程序从 PdfLoadedDocument Form 属性。这很好。

    我有另一个程序,它接收PDF文档,但这些文档似乎并不总是具有 类型 财产( 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"));
    

    似乎没有任何方法来设置/创建新的 类型 从Syncfusion文档中可以找到的内容添加到文档中。这使得这个程序中的任何内容都不能像我前面提到的程序中预期的那样运行(没有表单可以读取字段)。我是在这里错过了什么,还是走错了路?

    1 回复  |  直到 9 年前
        1
  •  1
  •   Broots Waymb    9 年前

    当现有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();
    

    如果您有任何问题,请告知我们。