나는 매월 수평 목록으로 월의 세로 목록을 작성합니다. 매일 나는 크기가 채워진 사각형을 추가하고 있습니다. 크기 및 색상은 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);
감사합니다. Bruno. Phrase in Cell 솔루션을 사용하고 위의 업데이트 된 코드를 추가했습니다. – DaveSav