2015-04-15 66 views
4

如何檢查iText上的複選框?如何檢查iText上的複選框?

form.setField("pt_gender_female", "On"); 
form.setField("pt_gender_female", true); 

我做了一對試驗和錯誤,但沒有一個工作。我搜查,但沒有找到完美的答案。

+0

嘗試獲取String [] states = form.getAppearanceStates(「pt_gender_female」);然後根據此String中的選項設置狀態[] –

+1

請下載免費電子書[The StackOverflow上的最佳iText問題](http://pages.itextpdf.com/ebook-stackoverflow-questions.html)。它包含許多問題的答案,包括[使用itextsharp檢查pdf複選框](http://stackoverflow.com/questions/19698771/checking-off-pdf-checkbox-with-itextsharp)(答案是關於iTextSharp,但它也適用於iText)。 –

回答

4
String states[] = stamper.getAcroFields().getAppearanceStates("pt_gender_female"); 
form.setField("pt_gender_female",states[1]); 

我試過了居留snipet。它檢查了複選框。

+0

請注意ArrayOutOfBounds - 「狀態」可能只包含一個元素。 「是的」在我的情況。注意到在Acrobat DC編輯PDF後。 –