itext生成pdf设置页眉页脚的实例详解
实例代码:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
/**
* itexttest
* itext生成pdf加入列表,注释等内容,同时设置页眉和页脚及页码等。
*/
package com.labci.itext.test;
import java.awt.color;
import java.io.filenotfoundexception;
import java.io.fileoutputstream;
import java.io.ioexception;
import com.lowagie.text.annotation;
import com.lowagie.text.document;
import com.lowagie.text.documentexception;
import com.lowagie.text.font;
import com.lowagie.text.headerfooter;
import com.lowagie.text.list;
import com.lowagie.text.listitem;
import com.lowagie.text.phrase;
import com.lowagie.text.rectangle;
import com.lowagie.text.pdf.basefont;
import com.lowagie.text.pdf.pdfwriter;
/**
* @author bill tu(tujiyue/iwtxokhtd)
* jun 6, 2011[4:10:35 pm]
*
*/
public class itextlist {
private final static string result_file= "itext_list.pdf" ;
public static void main(string []args){
document doc= new document();
try {
pdfwriter.getinstance(doc, new fileoutputstream(result_file));
basefont fontchinese= null ;
try {
fontchinese = basefont.createfont( "stsong-light" , "unigb-ucs2-h" ,basefont.not_embedded); //设置中文字体
} catch (ioexception e) {
e.printstacktrace();
}
font chinese = new font(fontchinese, 10 , font.normal);
/**
* headerfooter的第2个参数为非false时代表打印页码
* 页眉页脚中也可以加入图片,并非只能是文字
*/
headerfooter header= new headerfooter( new phrase( "这仅仅是个页眉,页码在页脚处" ,chinese), false );
//设置是否有边框等
// header.setborder(rectangle.no_border);
header.setborder(rectangle.bottom);
header.setalignment( 1 );
header.setbordercolor(color.red);
doc.setheader(header);
headerfooter footer= new headerfooter( new phrase( "-" ,chinese), new phrase( "-" ,chinese));
/**
* 0是靠左
* 1是居中
* 2是居右
*/
footer.setalignment( 1 );
footer.setbordercolor(color.red);
footer.setborder(rectangle.box);
doc.setfooter(footer);
/**
* 页眉页脚的设置一定要在open前设置好
*/
doc.open();
/**
* true:代表要排序,10代表序号与文字之间的间距
* false:代表不排序,则文字前的符号为"-"
*/
list itextlist= new list( true , 10 );
/**
* 也可以改变列表的符号[可选]
*
$$$
* 要改变列表符号时,上面的list构造方法第一参数值必须为false
*
$$$
* 可以使用字符串,chunk,image等作列表符号,如下
*/
//itextlist.setlistsymbol("*");
listitem firstitem= new listitem( "first paragraph" );
listitem seconditem= new listitem( "second paragraph" );
listitem thirditem= new listitem( "third paragraph" );
itextlist.add(firstitem);
itextlist.add(seconditem);
itextlist.add(thirditem);
doc.add(itextlist);
//添加注释,注释有标题和内容,注释可以是文本,内部链接,外部链接,图片等
annotation annotation= new annotation( "what's this?" , "it's a tree and it is not a big" );
doc.add(annotation);
doc.close();
} catch (filenotfoundexception e) {
e.printstacktrace();
} catch (documentexception e) {
e.printstacktrace();
}
}
}
|
工程结构图:
如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
原文链接:http://blog.csdn.net/tujiyue/article/details/6528372
相关文章
猜你喜欢
- ASP.NET自助建站系统中的用户注册和登录功能定制方法 2025-06-10
- ASP.NET自助建站系统的域名绑定与解析教程 2025-06-10
- 个人服务器网站搭建:如何选择合适的服务器提供商? 2025-06-10
- ASP.NET自助建站系统中如何实现多语言支持? 2025-06-10
- 64M VPS建站:如何选择最适合的网站建设平台? 2025-06-10
TA的动态
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
您的支持,是我们最大的动力!
热门文章
-
PHP实现登录搜狐广告获取广告联盟数据的方法【附demo源码】
2025-05-29 97 -
2025-05-25 74
-
2025-05-29 53
-
2025-05-27 21
-
2025-06-04 17
热门评论