javaif(val){
hashMap.put(mapKey,"\u2611");
}else{
hashMap.put(mapKey,"\u25A1");
}
}else{
hashMap.put(mapKey,mapValue);
这样子写,在pdf中能够将\u25A1转码展示出来,但是\u2611却展示不出来,这种情况下,需要设计pdf的字体样式,才能展示出来复选框。
String fontPath = "XXX/seguisym.ttf";
BaseFont baseFont = BaseFont.createFont(fontPath,BaseFont.IDENTITY_H,BaseFont.NOT_EMBEDDED);
Font font = new Font(baseFont);
for(int i = 0; i <= lastCell[0]; ++i) {
for(int j = 0; j <= lastCell[1]; ++j) {
PdfPCell pdfpCell = this.genPdfPCell(i, j);
if (pdfpCell != null) {
if (pdfpCell.getBackgroundColor().getRGB() != BaseColor.WHITE.getRGB() && spColor != null) {
pdfpCell.setBackgroundColor(spColor);
}
Phrase phrase = pdfpCell.getPhrase();
if("\u2611".equals(phrase.getContent())){
pdfpCell.setPhrase(new Paragraph("☑",font));
}
table.addCell(pdfpCell);
j += pdfpCell.getColspan() - 1;
}
}
}
通过获取填充内容信息,判断哪个单元格的文字样式需要更改,然后更改文件样式就行。