itext生成PDF设置页眉页脚的实例详解实例代码: package com.labci.itext.test; import java.awt.Color; import java.io.FileNotFoundException; im
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; 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 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)); footer.setAlignment(1); footer.setBorderColor(Color.red); footer.setBorder(Rectangle.BOX); doc.setFooter(footer); doc.open(); List itextList=new List(true,10); //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(); } } }
--结束END--
本文标题: itext生成PDF设置页眉页脚的实例详解
本文链接: https://lsjlt.com/news/223046.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
2024-05-24
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0