生活随笔
收集整理的這篇文章主要介紹了
pdf页眉页脚
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
/**
- ITextTest
- iText生成PDF加入列表,注釋等內(nèi)容,同時(shí)設(shè)置頁(yè)眉和頁(yè)腳及頁(yè)碼等。
/
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);//設(shè)置中文字體} catch (IOException e) {e.printStackTrace();}Font chinese = new Font(fontChinese, 10, Font.NORMAL); /*** HeaderFooter的第2個(gè)參數(shù)為非false時(shí)代表打印頁(yè)碼* 頁(yè)眉頁(yè)腳中也可以加入圖片,并非只能是文字*/HeaderFooter header=new HeaderFooter(new Phrase("這僅僅是個(gè)頁(yè)眉,頁(yè)碼在頁(yè)腳處",chinese),false);//設(shè)置是否有邊框等
// 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);/*** 頁(yè)眉頁(yè)腳的設(shè)置一定要在open前設(shè)置好*/doc.open();/*** true:代表要排序,10代表序號(hào)與文字之間的間距* false:代表不排序,則文字前的符號(hào)為"-"*/List itextList=new List(true,10);/*** 也可以改變列表的符號(hào)[可選]* $$$$$$$$$$$* 要改變列表符號(hào)時(shí),上面的List構(gòu)造方法第一參數(shù)值必須為false* $$$$$$$$$$$* 可以使用字符串,Chunk,Image等作列表符號(hào),如下*///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);//添加注釋,注釋有標(biāo)題和內(nèi)容,注釋可以是文本,內(nèi)部鏈接,外部鏈接,圖片等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();}
}
}
總結(jié)
以上是生活随笔為你收集整理的pdf页眉页脚的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。