ボタンの表があるフォームを作成しています。以下はその考え方を示しています。ラジオボタンの表の不思議な表示
Good OK Bad
Item1 [button] [button] [button]
Item2 [button] [button] [button]
各行はボタングループです。
私のプログラムは、上記のような小さなテーブルでも動作します。しかし、行または列が複数のページを保持する場合、表示は奇妙です。これは私のプログラムです:ときtable.setKeepTogether(false)
ここ
PdfPTable table = new PdfPTable(colHeaders.size() + 1 );
table.setWidthPercentage(100);
PdfPCell cell;
table.setSpacingBefore(10);
table.setSpacingAfter(0);
table.setKeepTogether(false); //tested "true" different display error
//upper-left corner empty cell
cell = new CustomPdfPCell();
cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
table.addCell(cell);
//header row
for (TableOfChoicesHeader c: colHeaders) {
String text = c.getText();
cell = new PdfPCell(new Phrase(text));
cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
table.addCell(cell);
}
List<PdfFormField> radioGroups= new ArrayList<PdfFormField>();
//for each row
for (TableOfChoicesHeader r: rowHeaders) {
//row header
String rowText = r.getText();
cell = new PdfPCell(new Phrase(rowText));
cell.setBackgroundColor(BaseColor.LIGHT_GRAY);
table.addCell(cell);
//for the current row row
String fieldName = "question" + q.getId() +"_" + r.getId().toString();
PdfFormField radiogroup = PdfFormField.createRadioButton(writer, true);
radiogroup.setFieldName(fieldName);
radioGroups.add(radiogroup);
for (TableOfChoicesHeader c: colHeaders) {
cell = new PdfPCell();
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
cell.setPadding(5);
cell.setCellEvent(new CheckboxCellEvent(fieldName, r.getId() + "_" + c.getId()));
table.addCell(cell);
}
}
document.add(table);
for (PdfFormField g: radioGroups) {
writer.addAnnotation(g);
}
はスクリーンショットです。表示は少し異なりますが、値がtrue
の場合はまだ変です。
更新
サミュエルのアプローチに従うことにより、私は、最初のページに表示されるラジオボタンを見ることができています。ただし、最初のページのボタンが2ページ目に表示されました。スクリーンショットを参照してください。
アップデート私は追加することにより、作業それを得た2
MyCellFieldに次の代わりに
のwriter.addAnnotation(radiogroup);
PdfFormField field = radio.getRadioField();
writer.addAnnotation(field);
理由を説明できません。 SamuelとBrunoに助けてくれてありがとう!
サミュエルを、私はポストを作る前にそれをテストしました。 document.add(table)の前にそれを行うと、ラジオボタンはまったく表示されません。思考をありがとう! – curious1
Samuelとcurious1さん、[RadioGroupMultiPage1](http://developers.itextpdf.com/examples/form-examples-itext5/creating-form-fields#1177-radiogroupmultipage1.java)と[RadioGroupMultiPage2]( http://developers.itextpdf.com/examples/form-examples/create-fields-table#1178-radiogroupmultipage2.java)。異なるページにラジオボタンを配布するときは、特別な注意が必要です。 –
こんにちは、あなたのご意見ありがとうございます。 2つの例を見て、ここでどのように役立つのか理解できません。基本的に、最初の例では、ラジオボタンを配置するページを手動で指定しています。 2番目の例では、私の状況と同様のページングを直接処理しませんが、私は奇妙な表示をしました。私がしたことをより具体的に教えてください。間違っていますか?ベスト。 – curious1