Itext的简单应用和学习
2015-08-02 12:09
267 查看
1.Itext使用需要使用itext.jar包。
2.Itext使用中文,主要有两种方式,下载itextasian.jar包,或者使用本地计算机字体。
本地计算机字体:
<span style="font-size:12px;"> BaseFont bfHei = BaseFont.createFont("c:/Windows/fonts/SIMHEI.TTF", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
Font font = new Font(bfHei, 32);
String text = "这是黑体字测试!";
document.add(new Paragraph(text, font));</span> 使用iTextAsian.jar中的字体:
<span style="font-size:12px;"> BaseFont.createFont("STSong-Light", "UniGB-UCS2-H",BaseFont.NOT_EMBEDDED);</span>3.Itext简单实例使用。
2.Itext使用中文,主要有两种方式,下载itextasian.jar包,或者使用本地计算机字体。
本地计算机字体:
<span style="font-size:12px;"> BaseFont bfHei = BaseFont.createFont("c:/Windows/fonts/SIMHEI.TTF", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
Font font = new Font(bfHei, 32);
String text = "这是黑体字测试!";
document.add(new Paragraph(text, font));</span> 使用iTextAsian.jar中的字体:
<span style="font-size:12px;"> BaseFont.createFont("STSong-Light", "UniGB-UCS2-H",BaseFont.NOT_EMBEDDED);</span>3.Itext简单实例使用。
Document document = new Document(PageSize.A3); document.addAuthor("Ryan"); document.addCreationDate(); try { PdfWriter.getInstance(document, new FileOutputStream("test.pdf")); document.open(); //Chunk chunk = new Chunk("Holle 乐", new Font(BaseFont.createFont("STSong-Light", "UniGB-UCS2-H",BaseFont.NOT_EMBEDDED), 32)); document.add(new Paragraph("Holle world!")); <span style="white-space:pre"> </span>Table table = new Table(3); table.setBorderWidth(1); table.setBorderColor(new Color(0, 0, 255)); table.setPadding(5); Cell cell = new Cell("header"); cell.setHeader(true); cell.setColspan(3); table.addCell(cell); cell = new Cell("example cell with colspan 1 and rowspan 2"); cell.setRowspan(2); cell.setBorderColor(new Color(255, 0, 0)); table.addCell(cell); table.addCell("1.1"); table.addCell("2.1"); table.addCell("1.2"); table.addCell("2.2"); table.addCell("cell test1"); cell = new Cell("big cell"); cell.setRowspan(2); cell.setColspan(2); cell.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0)); table.addCell(cell); table.addCell("cell test2"); document.add(table); //document.add(chunk); BaseFont bfHei = BaseFont.createFont("c:/Windows/fonts/SIMHEI.TTF", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); Font font = new Font(bfHei, 32); String text = "这是黑体字测试!"; document.add(new Paragraph(text, font)); document.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }
相关文章推荐
- 使用 Libki 来管理公共用户访问计算机
- 微型计算机的始祖:Altair 8800
- 通过手机、电脑远程开关机,Windows和linux机手机,电脑相互控制
- php实现用手机关闭计算机(电脑)的方法
- 用IE重起计算机或者关机的示例代码
- 一张图告诉你计算机编程语言的发展历史
- 计算机科学中32个常用的基础算法
- 不能在本地计算机启动 apache2.2解决方法
- python获取本地计算机名字的方法
- python获取当前计算机cpu数量的方法
- 第一台冯·诺伊曼结构量子计算机售价1000万美元
- 首台“混合”超级计算机突破千万亿次计算大关
- 代理服务器
- 回顾UNIX LINUX BSD架构
- 2008年最新最全计算机相关精品资源学习“宝典”系列典藏版电子书
- OSTA考试认证详细介绍之计算机
- 电脑硬件启动顺序
- Vmware安装报msi错误解决方案(官方翻译中文版)
- mysql修行练级之mysql新手入门常用命令
- Windows Server 2003的基本安装方法