2015-09-18 22 views
0

我在一些程序中使用了一些Syncfusion PDF工具。一個程序通過foreach循環從PdfLoadedDocumentForm屬性讀取字段(並根據一些屬性值進行一些記錄保存)。這工作正常。沒有窗體在Syncfusion PDF上添加字段

我有另一個程序,需要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")); 

似乎沒有要任何方式設置/創建一個新的Form從什麼我可以在Syncfusion找到添加到文檔中文檔。這使得這個程序中的任何內容都無法像我之前提到的程序那樣運行(沒有窗體可以讀取字段)。我在這裏錯過了什麼,或者以錯誤的方式解決了這個問題?

回答

1

我們必須在現有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(); 

請讓我們知道,如果您有任何顧慮。

相關問題