宋体不加粗"/>
java导出pdf字体宋体不加粗
由于PdfTemplate继承于PdfContentByte类,可以使用PdfContentByte方法来进行操作
Document doc = new Document();PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(filepath));
doc.open();PdfContentByte cb = writer.getDirectContent();
创建template并加到PdfContentByte里,template的状态位置是采用matrix方式来设置
PdfTemplate template = cb.createTemplate(width, height);
cb.addTemplate(template, 1f, 0f, 0f, 1f, 0f, 0f);
关于矩形变换,详细可以到wiki上学习
添加文字
template.saveState();
template.beginText();
template.moveText(5f, 5f); //坐标位置是相对template的左下角计算的//template.setColorFill(color);
template.showText("Test Text");
template.endText();
template.stroke();
template.restoreState();
设置文字粗体和斜体,由于没有招到设置的函数,采用其他方式来实现这个效果
换个想法可以根据matrix的思路用setTextMatrix方法来设置<
更多推荐
java导出pdf字体宋体不加粗
发布评论