OA办公软件与PDF文件联系紧密,PDF格式的文件也是办公人员必须掌握的!  设为首页 加入收藏夹 我来推荐 
您的位置:首页 > PDF应用技术 > PDF开发技术
PDF开发技术
iText操作Pdf如何输出中文
日期:2009-08-08 22:56:27 人气: 标签:
iText操作Pdf如何输出中文?
 
首先需要下载iTextAsian.jar包,可以到iText的主站上下,ireport也是需要这个包的。然后定义中文字体:

    private static final Font getChineseFont() {
         Font FontChinese = null;
        try {
             BaseFont bfChinese = BaseFont.createFont("STSong-Light",
                    "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
             FontChinese = new Font(bfChinese, 12, Font.NORMAL);
         } catch (DocumentException de) {
             System.err.println(de.getMessage());
         } catch (IOException ioe) {
             System.err.println(ioe.getMessage());
         }
        return FontChinese;
     }

我将产生中文字体封装在方法内,自定义一个段落PDFParagraph继承自Paragraph,默认使用中文字体:

class PDFParagraph extends Paragraph {
        public PDFParagraph(String content) {
            super(content, getChineseFont());
         }
     }


使用的时候就可以简化了:

Paragraph par = new PDFParagraph("你好");

共有条评论信息评论信息
栏目分类

站点说明 | 站点导航 | 站点公告 |
OAPDF.COM版权所有 2009 V1.1