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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

pdf页眉页脚

發布時間:2023/12/15 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 pdf页眉页脚 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

/**

  • 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();} }

}

總結

以上是生活随笔為你收集整理的pdf页眉页脚的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。