jsp 页面
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!doctype html>
<html>
<head>
<%@ include file="/WEB-INF/pages/globalweb/head/pagehead_v5.ini"%>
</head>
<body>
<iframe src="" marginwidth="0" target="_self" id="faFrame"
marginheight="0" frameborder="0" width="100%" height="945px"
style="overflow-x: hidden; overflow-y: auto;">
</iframe>
</body>
<script type="text/javascript">
$("#faFrame").attr("src",$.getURL(_path + "/fagl/faxxck_dyxx.html?
id=${faxx_id}"+'&dlbs='+$("#dlbs").val()));
</script>
</html>
Action 调用
public String dyxx(){
ByteArrayOutputStream bous = null;
try{
StringBuffer title = new StringBuffer("");
title.append(faxxckModel.getfamc());
//开始生成pdf
bous = service.createPdf(title,faxxckModel);
this.fileName = new String((title.toString() + ".pdf").getBytes(), "ISO8859-1");
this.inputStream = new ByteArrayInputStream(bous.toByteArray());
return Result.PDF_INLINE;
} catch (Exception e) {
logException(e);
return ERROR;
}finally{
IOUtils.closeQuietly(bous);
}
}
接口不写了
直接 实现类
@Override
public ByteArrayOutputStream createPdf(PyfaxxckModel model) throws DocumentException, IOException, ParseException, com.itextpdf.text.DocumentException{
int cellByHeight = 20;
//生成一个PDF文档
com.itextpdf.text.Document document = new com.itextpdf.text.Document(com.itextpdf.text.PageSize.A4,30,30,20,20);
//定义字节数组输出流对象,用于返回
ByteArrayOutputStream os = new ByteArrayOutputStream();
//获取pdf写对象
com.itextpdf.text.pdf.PdfWriter.getInstance(document, os);
//设置pdf文件的基本属性
document.addTitle("");
document.addAuthor("zfsoft");
document.addSubject("zfsoft");
document.addKeywords("zfsoft");
document.addCreator("zfsoft");
document.open();
//定义字体
com.itextpdf.text.pdf.BaseFont bfChinese = com.itextpdf.text.pdf.BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
com.itextpdf.text.pdf.BaseFont bfChineseWHXW = com.itextpdf.text.pdf.BaseFont.createFont(ServletActionContext.getServletContext().getRealPath("/")+"/font/STXINWEI.TTF", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);//华文新魏
com.itextpdf.text.pdf.BaseFont bfChineseHT = com.itextpdf.text.pdf.BaseFont.createFont(ServletActionContext.getServletContext().getRealPath("/")+"/font/SIMHEI.TTF", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);//黑体
com.itextpdf.text.pdf.BaseFont bfChineseFS = com.itextpdf.text.pdf.BaseFont.createFont(ServletActionContext.getServletContext().getRealPath("/")+"/font/SIMFANG.TTF", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);//仿宋
com.itextpdf.text.Font HeadFont = new com.itextpdf.text.Font(bfChinese,36,Font.NORMAL);
com.itextpdf.text.Font HeadSchoolFont = new com.itextpdf.text.Font(bfChineseWHXW,36,Font.BOLD);
com.itextpdf.text.Font cellFontHT = new com.itextpdf.text.Font(bfChineseHT, 16, Font.BOLD);
com.itextpdf.text.Font cellFontFS = new com.itextpdf.text.Font(bfChineseFS, 14, Font.NORMAL);
com.itextpdf.text.Font cellFont = new com.itextpdf.text.Font(bfChinese, 16, Font.NORMAL);
com.itextpdf.text.Font smallCellFont = new com.itextpdf.text.Font(bfChinese, 12, Font.NORMAL);
com.itextpdf.text.Font smallCellFontB = new com.itextpdf.text.Font(bfChinese, 12, Font.BOLD);
PyfaxfyqModel pyfaxfyqModel = new PyfaxfyqModel();
pyfaxfyqModel.setPyfaxx_id(model.getPyfaxx_id());
List<Map<String, String>> xnxqDzxxList = dao.getXnxqDzxx(model.getId());
if (xnxqDzxxList.size()>0) {
for(int j=0; j<xnxqDzxxList.size(); j++){
document.newPage();
document.add(JwglxtFrequentlyUserUtil.setParagraph("进程表", cellFontHT, Element.ALIGN_CENTER, 40, 16, 16));
com.itextpdf.text.pdf.PdfPTable table = new com.itextpdf.text.pdf.PdfPTable((int)9);
int[] BGBody = new int[]{24,42,18,18,15,15,15,10,20};
table.setWidths(BGBody);
table.setWidthPercentage(100f);
table.setSpacingAfter(10);
table.addCell(JwglxtFrequentlyUserUtil.makeCell("号", 1, 2, PdfPCell.ALIGN_CENTER, PdfPCell.ALIGN_MIDDLE, smallCellFont, cellByHeight));
table.addCell(JwglxtFrequentlyUserUtil.makeCell("名称", 1, 2, PdfPCell.ALIGN_CENTER, PdfPCell.ALIGN_MIDDLE, smallCellFont, cellByHeight));
table.addCell(JwglxtFrequentlyUserUtil.makeCell("类别", 1, 2, PdfPCell.ALIGN_CENTER, PdfPCell.ALIGN_MIDDLE, smallCellFont, cellByHeight));
table.addCell(JwglxtFrequentlyUserUtil.makeCell("性质", 1, 2, PdfPCell.ALIGN_CENTER, PdfPCell.ALIGN_MIDDLE, smallCellFont, cellByHeight));
table.addCell(JwglxtFrequentlyUserUtil.makeCell("分配", 2, 1, PdfPCell.ALIGN_CENTER, PdfPCell.ALIGN_MIDDLE, smallCellFont, cellByHeight));
table.addCell(JwglxtFrequentlyUserUtil.makeCell("方式", 1, 2, PdfPCell.ALIGN_CENTER, PdfPCell.ALIGN_MIDDLE, smallCellFont, cellByHeight));
table.addCell(JwglxtFrequentlyUserUtil.makeCell("分", 1, 2, PdfPCell.ALIGN_CENTER, PdfPCell.ALIGN_MIDDLE, smallCellFont, cellByHeight));
table.addCell(JwglxtFrequentlyUserUtil.makeCell("\r\n(周)", 1, 2, PdfPCell.ALIGN_CENTER, PdfPCell.ALIGN_MIDDLE, smallCellFont, cellByHeight));
table.addCell(JwglxtFrequentlyUserUtil.makeCell("理", 1, PdfPCell.ALIGN_CENTER, PdfPCell.ALIGN_MIDDLE, smallCellFont, cellByHeight));
table.addCell(JwglxtFrequentlyUserUtil.makeCell("实", 1, PdfPCell.ALIGN_CENTER, PdfPCell.ALIGN_MIDDLE, smallCellFont, cellByHeight));
String njm = xnxqDzxxList.get(j).get("JYXDNJDM");
String xqm = xnxqDzxxList.get(j).get("JYXDXQM");
String pm = xnxqDzxxList.get(j).get("PM");
String xbx = "";
double xf = 0;
double zdxdxf = 0;
double bxxf = 0;
double xxxf = 0;
double ksxf = 0; //
List<Map<String,String>> kcxxList = dao.cxPyfakcxxByXnxqInfo(njm,xqm,model.getId());
if (kcxxList.size()>0) {
for (Map<String, String> kcxxMap : kcxxList) {
table.addCell(JwglxtFrequentlyUserUtil.makeCell(kcxxMap.get("H"), 1, PdfPCell.ALIGN_CENTER, PdfPCell.ALIGN_MIDDLE, smallCellFont, cellByHeight));
table.addCell(JwglxtFrequentlyUserUtil.makeCell(kcxxMap.get("MC"), 1, PdfPCell.ALIGN_CENTER, PdfPCell.ALIGN_MIDDLE, smallCellFont, cellByHeight));
table.addCell(JwglxtFrequentlyUserUtil.makeCell(kcxxMap.get("MC"), 1, PdfPCell.ALIGN_CENTER, PdfPCell.ALIGN_MIDDLE, smallCellFont, cellByHeight));
table.addCell(JwglxtFrequentlyUserUtil.makeCell(kcxxMap.get("ZMC"), 1, PdfPCell.ALIGN_CENTER, PdfPCell.ALIGN_MIDDLE, smallCellFont, cellByHeight));
table.addCell(JwglxtFrequentlyUserUtil.makeCell(kcxxMap.get("X_LL"), 1, PdfPCell.ALIGN_CENTER, PdfPCell.ALIGN_MIDDLE, smallCellFont, cellByHeight));
table.addCell(JwglxtFrequentlyUserUtil.makeCell(kcxxMap.get("M_SJ"), 1, PdfPCell.ALIGN_CENTER, PdfPCell.ALIGN_MIDDLE, smallCellFont, cellByHeight));
table.addCell(JwglxtFrequentlyUserUtil.makeCell(kcxxMap.get("KMC"), 1, PdfPCell.ALIGN_CENTER, PdfPCell.ALIGN_MIDDLE, smallCellFont, cellByHeight));
table.addCell(JwglxtFrequentlyUserUtil.makeCell(kcxxMap.get("X"), 1, PdfPCell.ALIGN_CENTER, PdfPCell.ALIGN_MIDDLE, smallCellFont, cellByHeight));
table.addCell(JwglxtFrequentlyUserUtil.makeCell(kcxxMap.get("Z"), 1, PdfPCell.ALIGN_CENTER, PdfPCell.ALIGN_MIDDLE, smallCellFont, cellByHeight));
xbx=kcxxMap.get("XBX");
xf = Double.parseDouble(kcxxMap.get("X"));
if (xbx.equals("bx")) {
bxxf += xf;
}
if (xbx.equals("xx")) {
xxxf += xf;
}
if (kcxxMap.get("KHFSDM").equals("1")) {
ksxf += xf;
}
zdxdxf = bxxf +xxxf;
}
table.addCell(JwglxtFrequentlyUserUtil.makeCell( "分 ", 9,1, PdfPCell.ALIGN_CENTER, PdfPCell.ALIGN_MIDDLE, smallCellFontB, cellByHeight));
}
document.add(table);
}
}
document.close();
return os;
}