本次对itext的研究主要针对的是pdf 的table,主要应用于打印单据。
框架为jfinal,表头信息中有动态数据,比如:年月日等。
下面直接贴代码:
/*** 前台调用打印方法
* LMM
*
*/
public void printStorage(){
try {
Integer id=getParaToInt("pid",0);//获取前台传数据
List<Stordetail> stolist=Stordetail.dao.find("select s.*,st.*,p.pub_name,e.edi_name,i.iss_name from stordetail s " +
" left join publish p on s.pub_id=p.pub_id left join edition e on s.edi_id=e.edi_id" +
" left join storsummary st on s.stsu_id=st.stsu_id " +
" left join issue i on s.iss_id=i.iss_id where s.stsu_id="+id+" order by det_id desc");//需要显示的数据
Storsummary stsu=Storsummary.dao.findById(id);//需要显示的数据
//start print
Rectangle rec = new Rectangle(240*2.5f,140*2.5f); //自定义纸张大小
Document document = new Document(rec,10,10,50,50);//纸张大小,marginleft,marginright,margintop,marginbottom
//设置输出的位置并把对象装入输出对象中
PdfWriter writer=PdfWriter.getInstance(document, new FileOutputStream(PathKit.getWebRootPath() + "/temp/printStorage.pdf"));
//设置pdf每页的页眉和页脚
writer.setPageEvent(new HeadFootInfoPdfPageEvent(stolist,stsu));
//打开文档
document.open();
//设置中文字体
BaseFont baseFont = BaseFont.createFont("C:/WINDOWS/Fonts/SIMSUN.TTC,1", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);//配置中文
//字体和字号
Font font = new Font(baseFont, 12, Font.NORMAL);
//title
String[] date=stolist.get(0).getDate("stsu_data").toString().split("-");
//table start包括table的每列的宽度
PdfPTable table = new PdfPTable(new float[]{20f,70f,30f,50f,100f});
table.setSpacingBefore(5);//
table.setSpacingAfter(5);
table.setHeaderRows(1);//设置每页的table都要显示head
//head
PdfPHeaderCell head

本文介绍如何在iText高版本中创建PDF文档,并展示动态的页眉和页脚信息,例如日期和入库单据详情。通过自定义PdfPageEventHelper子类,设置中文文字和内容,实现在每一页上显示不同数据。
最低0.47元/天 解锁文章
802

被折叠的 条评论
为什么被折叠?



