月の縦リストを作成し、毎月の水平日のリストを作成します。私は毎日、大きさと色のついた矩形を追加しています。サイズと色はdbクエリの値に依存します。PdfPCellでテンプレート要素を整列する方法
私は他のすべてが離れて長方形の位置から、(長方形の大きさ、矩形の色)正常に動作this answer
で提供PdfPTable
、PdfPCell
とcbCreateTemplate
を使用しています:それは常にに位置しています0,0でも私はV & Hポジショニングを設定しました。コードの抜粋は以下の通りです。お知らせ下さい。
int Severity = args.getPLR().get(i).getItems().get(j).getItems().get(itemIndex).getSeverity();
Severity = Severity + 5; //plump up, so that max (10) should fill the cell
PdfPCell cell = new PdfPCell();
cell.setPadding(0);
template = cb.createTemplate(Severity, Severity);
template.setLineWidth(0.5f);
template.rectangle(0, 0, Severity, Severity);
//we should switch the color
//based on the Severity
switch ((Severity-5)) {
case 0:
template.setColorFill(Color.GREEN);
break;
case 1:
template.setColorFill(Color.GREEN);
break;
case 2:
template.setColorFill(Color.YELLOW);
break;
case 3:
template.setColorFill(Color.YELLOW);
break;
case 4:
template.setColorFill(Color.YELLOW);
break;
case 5:
template.setColorFill(Color.ORANGE);
break;
case 6:
template.setColorFill(Color.ORANGE);
break;
case 7:
template.setColorFill(Color.ORANGE);
break;
case 8:
template.setColorFill(Color.RED);
break;
case 9:
template.setColorFill(Color.RED);
break;
case 10:
template.setColorFill(Color.RED);
break;
}
template.fill();
img = Image.getInstance(template);
chunk = new Chunk(img, 0f, 0f);
cell.addElement(chunk);
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
painTable.addCell(cell);
これが示されているもののグラフィックです:
それはセンター/センターでなければなりません。どこが間違っていたのですか?
これが受け入れられた溶液を使用して更新されたコードの一部です:
img = Image.getInstance(template);
chunk = new Chunk(img, 0f, 0f);
Phrase severityChunk = new Phrase(chunk);
PdfPCell cell = new PdfPCell(severityChunk);
cell.setPadding(0);
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
painTable.addCell(cell);
ありがとうございました。私はCellソリューションでPhraseを使用し、上記の更新されたコードを追加しました。 – DaveSav