日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

IText 生成页脚页码

發(fā)布時間:2023/11/30 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 IText 生成页脚页码 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

做doc文檔報表的時候可能遇到這樣的需求:

每一個頁面需要頁碼,用IText可以完成這樣的需求。

IText生成doc文檔需要三個包:iTextAsian.jar,iText-rtf-2.1.4.jar,iText-2.1.4.jar

代碼親測無錯,如下所示:

import com.lowagie.text.*;
import com.lowagie.text.Font;
import com.lowagie.text.rtf.RtfWriter2;

import java.awt.*;
import java.io.FileOutputStream;

/**
?* 生成頁腳頁碼
?* User: HYY
?* Date: 13-8-1
?* Time: 下午9:54
?* To change this template use File | Settings | File Templates.
?*/
public class FooterTest {
??? /**
???? * @param args
???? */
??? public static void main(String[] args) throws Exception {
??????? // 創(chuàng)建word文檔,并設(shè)置紙張的大小
??????? Document document = new Document(PageSize.A4);
??????? //設(shè)置存放位置
??????? RtfWriter2.getInstance(document, new FileOutputStream("C:\\Documents and Settings\\Administrator\\桌面//1.doc"));
??????? document.open();

??????? //正文(為了生成兩頁紙)
??????? Table table = new Table(7,60);
??????? document.add(table);

??????? //————————頁腳設(shè)置————————
??????? //頁腳段落(這里為空,可以自己添加文字)
??????? Paragraph paraFooter = new Paragraph();
??????? Font font = new Font();
??????? //頁腳的字體大小
??????? font.setSize(12f);
??????? font.setColor(new Color(0,0,0));
??????? paraFooter.setFont(font);
??????? paraFooter.setAlignment("center");
??????? //(參數(shù)一)頁腳的段落?? 和? (參數(shù)二)是否有頁碼
??????? HeaderFooter footer = new HeaderFooter(paraFooter, false);
??????? //頁腳的對齊方式(應(yīng)該在footer設(shè)置而不是段落中設(shè)置)
??????? footer.setAlignment(1);
??????? document.setFooter(footer);

??????? document.close();
??? }

}

?

附:

HeaderFooter類的構(gòu)造器官方文檔:

HeaderFooter(Phrase?before, boolean?numbered)
??????????Constructs a Header-object with a pagenumber at the end.

由上可知,第二個參數(shù)是專門設(shè)置頁腳頁碼的參數(shù)。

true表示生成頁碼,false表示不生成頁碼。

轉(zhuǎn)載于:https://www.cnblogs.com/wuyou/p/3236671.html

總結(jié)

以上是生活随笔為你收集整理的IText 生成页脚页码的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。