itext基本编辑单元
来源:互联网 发布:c#冒泡排序的算法思路 编辑:程序博客网 时间:2024/06/04 19:50
在itext的com.lowagie.text包中有Chunk,Phrase,Paragraph这三种text编辑单元
其中Chunk是最小的单元
也就是说Paragraph可以包含多个Phrase,Phrase可以包含多个Chunk
下面是Chunk的例子
我们一般不使用Chunk生成文本,因为Chunk不能自动换行,而是使用Phrase代替
Phrase已经满足大部分需求,但是如果我们想要一个分成几段来显示文本,可以使用
phrase.add("\n");
也可以通过Paragraph来实现
其中Chunk是最小的单元
也就是说Paragraph可以包含多个Phrase,Phrase可以包含多个Chunk
下面是Chunk的例子
public class Chunk_Example {public Chunk_Example() throws Exception{Document document = new Document();PdfWriter.getInstance(document, new FileOutputStream("chunk_example.pdf"));document.open();Font font = new Font(Font.COURIER, 10, Font.BOLD); // 设置fontfont.setColor(new Color(0x92, 0x90, 0x83));Chunk chunk = new Chunk("testing text element", font); // 初始化Chunkchunk.setBackground(new Color(0xff, 0xe4, 0x00)); // 设置背景document.add(chunk); // 添加chunk到文档document.close();}public static void main(String[] args) {try{Chunk_Example textExample = new Chunk_Example();}catch(Exception e){System.out.println(e);}}}
我们一般不使用Chunk生成文本,因为Chunk不能自动换行,而是使用Phrase代替
public class Phrase_Example {public Phrase_Example() throws Exception{Document document = new Document();PdfWriter.getInstance(document, new FileOutputStream("phrase_example.pdf"));document.open();Font font = new Font(Font.COURIER, 10, Font.BOLD);font.setColor(new Color(0x92, 0x90, 0x83));Chunk chunk = new Chunk("testing text element ", font);chunk.setBackground(new Color(0xff, 0xe4, 0x00));Phrase phrase = new Phrase(20, "This is initial text. "); //初始化Phrase,有20像素的间距for(int i=0; i < 10; i++){phrase.add(chunk); // 添加110个Chunk到Phrase}document.add(phrase); document.close();}public static void main(String[] args) {try{Phrase_Example textExample = new Phrase_Example();}catch(Exception e){System.out.println(e);}}}
Phrase已经满足大部分需求,但是如果我们想要一个分成几段来显示文本,可以使用
phrase.add("\n");
也可以通过Paragraph来实现
public class Paragraph_Example {public Paragraph_Example() throws Exception{Document document = new Document();PdfWriter.getInstance(document, new FileOutputStream("paragraph_example.pdf"));document.open();Font font = new Font(Font.COURIER, 10, Font.BOLD);font.setColor(new Color(0x92, 0x90, 0x83));Chunk chunk = new Chunk("testing text element ", font);chunk.setBackground(new Color(0xff, 0xe4, 0x00));Phrase phrase = new Phrase(20, "This is initial text. "); for(int i=0; i < 10; i++){phrase.add(chunk); }Paragraph paragraph = new Paragraph(); paragraph.add(phrase);//添加phrase对象document.add(paragraph); //添加paragraphdocument.add(paragraph); //添加paragraphdocument.close();}public static void main(String[] args) {try{Paragraph_Example textExample = new Paragraph_Example();}catch(Exception e){System.out.println(e);}}}
引用
http://www.geek-tutorials.com/java/itext/insert_control_text.php
阅读全文
0 0
- itext基本编辑单元
- iText编辑Pdf模板
- iText编辑Pdf模板
- java利用itext编辑pdf
- java利用itext编辑pdf
- swing jtable 单元编辑事件
- iText之pdf书签编辑工具
- java中利用itext编辑pdf
- java中利用itext编辑pdf
- 利用itext工具编辑生成pdf
- java中利用itext编辑pdf
- SlickGrid example 3a: 可编辑单元
- SS7基本信号单元格式
- Delphi单元文件基本结构
- android基本程序单元Activity
- DirectShow的基本单元:Filter
- makefile基本组成单元:规则
- OpenGl绘制基本单元注解
- Java 缩短UUID为22位
- itext中文问题
- 深入浅出 java 回调原理
- Mac的eclipse使用External Tools定位class
- N个人过河问题
- itext基本编辑单元
- CDH5.7.2搭建
- turn on AUTOCOMMIT with toad
- PHP,Form提交多行数据处理
- Oracle PRAGMA EXCEPTION_INIT
- 归并排序
- itext PdfPTable width
- mac的环境变量修改顺序
- rmdir命令