package com.infrastructure.project.common.util;

import java.awt.Color;
import java.io.File;
import java.io.FileOutputStream;
import java.util.List;

import com.infrastructure.project.common.SysConstant;
import com.lowagie.text.Cell;
import com.lowagie.text.Document;
import com.lowagie.text.Element;
import com.lowagie.text.Font;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Phrase;
import com.lowagie.text.Rectangle;
import com.lowagie.text.Table;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfWriter;

public class ExportPdfUtil {
	public static void exportPdf(String fileName,String filePath,List listLable ,List listData) {
		Document document = new Document(PageSize.A4.rotate(), 50, 50, 50, 50);
		try {
			File file = new File(filePath);
			BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED); 
			Font FontChinese = new Font(bfChinese, 12, Font.NORMAL);
			Font FontChina = new Font(bfChinese, 24, Font.NORMAL);
			if (!file.exists()) {
				file.mkdirs();
			}
			PdfWriter.getInstance(document, new FileOutputStream(filePath+fileName+SysConstant.nameSuffix.NAMESUFFIX_PDF));
			document.open();
			Table datatable = new Table(listLable.size());
			datatable.setWidth(100);
			datatable.setPadding(3);
			Cell cell = new Cell(new Phrase(fileName,FontChina));
			
			cell.setHorizontalAlignment(Element.ALIGN_CENTER);
			cell.setLeading(30);
			cell.setColspan(listLable.size());
			cell.setBorder(Rectangle.NO_BORDER);
			cell.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0));
			datatable.addCell(cell);
			datatable.setBorderWidth(2);
			datatable.setAlignment(1);
			for(int i =0;i<listLable.size();i++){
				datatable.addCell(new Paragraph(listLable.get(i).toString(),FontChinese));
			}
			datatable.endHeaders();
			datatable.setBorderWidth(1);
			for (int j = 0; j < listData.size(); j++) {
				List a = (List) listData.get(j);
				for(int o = 0;o<a.size();o++){
					datatable.addCell(new Paragraph(a.get(o) == null ?"":a.get(o).toString(),FontChinese));
				}
			}

			document.add(datatable);
		} catch (Exception e) {
			e.printStackTrace();
		}
		document.close();
	}
}
最近下载更多
wbbhappy  LV13 1月13日
sswert  LV2 2022年3月18日
天险无涯  LV15 2022年1月19日
北凉 _徐凤年  LV4 2021年12月21日
aaaahao  LV13 2021年7月25日
alexgyp  LV6 2021年7月9日
soscat2000  LV3 2020年7月6日
libo1212  LV8 2020年5月9日
zmy001  LV11 2020年4月8日
490239876  LV7 2020年2月27日
最近浏览更多
wbbhappy  LV13 1月10日
2317696509  LV6 2023年12月15日
1529860026  LV24 2023年7月6日
yangxb2  LV10 2022年9月19日
Hachi6  LV13 2022年9月19日
jinnitom 2022年9月14日
暂无贡献等级
8战魂5无双8  LV43 2022年9月13日
是你爸爸啊100  LV5 2022年8月8日
暂无贡献等级
rookie_58  LV2 2022年6月2日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友