分类: Java
2010-10-11 14:01:38
import java.awt.Color; import java.io.FileOutputStream; import java.io.IOException; import com.lowagie.text.Document; import com.lowagie.text.DocumentException; import com.lowagie.text.Element; import com.lowagie.text.Font; import com.lowagie.text.HeaderFooter; import com.lowagie.text.PageSize; import com.lowagie.text.Paragraph; import com.lowagie.text.Phrase; import com.lowagie.text.Rectangle; import com.lowagie.text.pdf.BaseFont; import com.lowagie.text.pdf.PdfWriter; /** * 页码 * */ public class Simple7 { @SuppressWarnings("deprecation") public static void main(String[] args) throws DocumentException, IOException { Document doc = new Document(PageSize.B5); BaseFont bfChinese = BaseFont.createFont("STSongStd-Light", "UniGB-UCS2-H", false); Font fontChinese = new Font(bfChinese, 12, Font.NORMAL, Color.GREEN); PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream( "E:/HelloWorld.pdf")); // HeaderFooter footer = new HeaderFooter(new Phrase(" 第", fontChinese), // new Phrase(" 页", fontChinese)); HeaderFooter footer = new HeaderFooter(new Phrase("页码:", fontChinese), true); footer.setBorder(Rectangle.NO_BORDER); footer.setAlignment(Element.ALIGN_CENTER); doc.setFooter(footer); doc.open(); for (int i = 0; i < 20; i++) { doc.add(new Paragraph("Test.......")); doc.add(new Paragraph("Test.......")); doc.add(new Paragraph("Test.......")); } doc.close(); } }