java导出pdf字体宋体不加粗

编程入门 行业动态 更新时间:2024-10-10 03:25:12

java导出pdf字体<a href=https://www.elefans.com/category/jswz/34/1735503.html style=宋体不加粗"/>

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字体宋体不加粗

本文发布于:2024-02-27 19:39:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1765839.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:宋体   字体   加粗   java   pdf

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!