//导出
public void ScoringAnnouncementdownLoad() throws MalformedURLException, IOException, DocumentException, FileStoreException {
ActionContext act = ActionContext.getContext();
AclUserBean logonUser = (AclUserBean) act.getSession().get(Constant.LOGON_USER);
String acnt=logonUser.getAcnt();
ResponseWrapper response = act.getResponse();
OutputStream os = null;
String fileName = "特约店综合评分.pdf";
fileName = new String(fileName.getBytes("GB2312"), "ISO8859-1");
Document document=new Document(PageSize.A0, 10, 10,10, 10);
Rectangle pageRect=document.getPageSize();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfWriter writer = PdfWriter.getInstance(document, baos);
Paragraph emptyLine10 = new Paragraph(10,"");
BaseFont bf= BaseFont.createFont("C:/WINDOWS/Fonts/SIMYOU.TTF", BaseFont.IDENTITY_H,BaseFont.NOT_EMBEDDED);
Font fontChinese10 = new Font(bf,10, Font.NORMAL);
//页尾
document.setFooter(createFooter(fontChinese10));
//页头
document.setHeader(createHeader(fontChinese10));
//水印
Watermark W =new Watermark(acnt);
writer.setPageEvent(W);
//打开
document.open();
//添加空行
document.add(emptyLine10);
//加数据
document.add(createTab(fontChinese10));
//创建新页
document.newPage();
//关闭
document.close();
//生成是否保存
response.addHeader("Content-Disposition", "attachment;filename=" + fileName);
response.setContentType("application/pdf");
response.setContentLength(baos.size());
os = response.getOutputStream();
baos.writeTo(os);
//关闭流
os.flush();
os.close();
}
private HeaderFooter createFooter(Font fontChinese10){
String footStr1 = "页尾 ";
HeaderFooter footer=new HeaderFooter(new Phrase(footStr1,fontChinese10),new Phrase(" \t\t",fontChinese10));
footer.setAlignment(Element.ALIGN_RIGHT);
footer.setBottom(0);
return footer;
}
private HeaderFooter createHeader(Font fontChinese10){
String footStr1 = "页头 ";
HeaderFooter footer=new HeaderFooter(new Phrase(footStr1,fontChinese10), false) ;
footer.setAlignment(Element.ALIGN_CENTER);
footer.setTop(0);
footer.setLeft(0);
return footer;
}
//数据
private PdfPTable createTab(Font fontChinese12){
try {
PdfPTable tab = new PdfPTable(27);//多少列
//tab.setTotalWidth(100); //固定宽度
tab.setWidths(new int[]{20,20,40,50,50,50,50,45,45,40,40,60,90,55,75,50,40,40,78,55,50,50,60,50,50,35,50}); //每列的宽度, 只针对固 定宽度有效;如果表格使用百分比设置总宽度的话,那这里也就是使用百分比.
tab.setWidthPercentage(100);// 表格宽度设置为100%
List<Map<String, Object>> data = tabData();
PdfPCell cell_temp = null;
cell_temp = new PdfPCell(new Paragraph("排名", fontChinese12));
tab.addCell(cell_temp);
cell_temp = new PdfPCell(new Paragraph("大区", fontChinese12));
tab.addCell(cell_temp);
cell_temp = new PdfPCell(new Paragraph("省份", fontChinese12));
tab.addCell(cell_temp);
cell_temp = new PdfPCell(new Paragraph("特约店简称", fontChinese12));
tab.addCell(cell_temp);
cell_temp = new PdfPCell(new Paragraph("特约店代码", fontChinese12));
tab.addCell(cell_temp);
cell_temp = new PdfPCell(new Paragraph("开业时间", fontChinese12));
tab.addCell(cell_temp);
cell_temp = new PdfPCell(new Paragraph("提车达成率12%", fontChinese12));
tab.addCell(cell_temp);
cell_temp = new PdfPCell(new Paragraph("登录达成率12%", fontChinese12));
tab.addCell(cell_temp);
cell_temp = new PdfPCell(new Paragraph("提车贡献率 10%", fontChinese12));
tab.addCell(cell_temp);
cell_temp = new PdfPCell(new Paragraph("市占率6%", fontChinese12));
tab.addCell(cell_temp);
cell_temp = new PdfPCell(new Paragraph("销售满意度6%", fontChinese12));
tab.addCell(cell_temp);
cell_temp = new PdfPCell(new Paragraph("客流目标达成率 6%", fontChinese12));
tab.addCell(cell_temp);
cell_temp = new PdfPCell(new Paragraph("电话网络到店目标达成率2%", fontChinese12));
tab.addCell(cell_temp);
cell_temp = new PdfPCell(new Paragraph("二手车目标达成率6%", fontChinese12));
tab.addCell(cell_temp);
cell_temp = new PdfPCell(new Paragraph("电话网络到店目标达成率2%", fontChinese12));
tab.addCell(cell_temp);
cell_temp = new PdfPCell(new Paragraph("售后满意度8%", fontChinese12));
tab.addCell(cell_temp);
cell_temp = new PdfPCell(new Paragraph("人员培训4%", fontChinese12));
tab.addCell(cell_temp);
cell_temp = new PdfPCell(new Paragraph("保养达成率8%", fontChinese12));
tab.addCell(cell_temp);
cell_temp = new PdfPCell(new Paragraph("管理内用户再次回店保养率4%", fontChinese12));
tab.addCell(cell_temp);
cell_temp = new PdfPCell(new Paragraph("保险产品 达成率8%", fontChinese12));
tab.addCell(cell_temp);
cell_temp = new PdfPCell(new Paragraph("用品单车产值4%", fontChinese12));
tab.addCell(cell_temp);
cell_temp = new PdfPCell(new Paragraph("保养单车达成率8%", fontChinese12));
tab.addCell(cell_temp);
cell_temp = new PdfPCell(new Paragraph("售后有责投诉(扣分项)", fontChinese12));
tab.addCell(cell_temp);
cell_temp = new PdfPCell(new Paragraph("售后得分", fontChinese12));
tab.addCell(cell_temp);
cell_temp = new PdfPCell(new Paragraph("总分", fontChinese12));
tab.addCell(cell_temp);
cell_temp = new PdfPCell(new Paragraph("是否参评", fontChinese12));
tab.addCell(cell_temp);
cell_temp = new PdfPCell(new Paragraph("取消参评原因", fontChinese12));
tab.addCell(cell_temp);
if(data!=null){
for (int i = 0; i < data.size(); i++) {
cell_temp = new PdfPCell(new Paragraph(data.get(i).get("RANKING")+"", fontChinese12));
tab.addCell(cell_temp);
cell_temp = new PdfPCell(new Paragraph(data.get(i).get("REGION_NAME")+"", fontChinese12));
tab.addCell(cell_temp);
cell_temp = new PdfPCell(new Paragraph(data.get(i).get("PROVINCE")+"", fontChinese12));
tab.addCell(cell_temp);
cell_temp = new PdfPCell(new Paragraph(data.get(i).get("DEALER_SHORTNAME")+"", fontChinese12));
tab.addCell(cell_temp);
cell_temp = new PdfPCell(new Paragraph(data.get(i).get("DEALER_CODE")+"", fontChinese12));
tab.addCell(cell_temp);
cell_temp = new PdfPCell(new Paragraph(data.get(i).get("OPEN_DATE")+"", fontChinese12));
tab.addCell(cell_temp);
cell_temp = new PdfPCell(new Paragraph(data.get(i).get("V1001")+"", fontChinese12));
tab.addCell(cell_temp);
cell_temp = new PdfPCell(new Paragraph(data.get(i).get("V1002")+"", fontChinese12));
tab.addCell(cell_temp);
cell_temp = new PdfPCell(new Paragraph(data.get(i).get("V1003")+"", fontChinese12));
tab.addCell(cell_temp);
cell_temp = new PdfPCell(new Paragraph(data.get(i).get("V1004")+"", fontChinese12));
tab.addCell(cell_temp);
cell_temp = new PdfPCell(new Paragraph(data.get(i).get("V1005")+"", fontChinese12));
tab.addCell(cell_temp);
cell_temp = new PdfPCell(new Paragraph(data.get(i).get("V1006")+"", fontChinese12));
tab.addCell(cell_temp);
cell_temp = new PdfPCell(new Paragraph(data.get(i).get("V1007")+"", fontChinese12));
tab.addCell(cell_temp);
cell_temp = new PdfPCell(new Paragraph(data.get(i).get("V1008")+"", fontChinese12));
tab.addCell(cell_temp);
cell_temp = new PdfPCell(new Paragraph(data.get(i).get("V1999")+"", fontChinese12));
tab.addCell(cell_temp);
cell_temp = new PdfPCell(new Paragraph(data.get(i).get("V2001")+"", fontChinese12));
tab.addCell(cell_temp);
cell_temp = new PdfPCell(new Paragraph(data.get(i).get("V2002")+"", fontChinese12));
tab.addCell(cell_temp);
cell_temp = new PdfPCell(new Paragraph(data.get(i).get("V2003")+"", fontChinese12));
tab.addCell(cell_temp);
cell_temp = new PdfPCell(new Paragraph(data.get(i).get("V2004")+"", fontChinese12));
tab.addCell(cell_temp);
cell_temp = new PdfPCell(new Paragraph(data.get(i).get("V2005")+"", fontChinese12));
tab.addCell(cell_temp);
cell_temp = new PdfPCell(new Paragraph(data.get(i).get("V2006")+"", fontChinese12));
tab.addCell(cell_temp);
cell_temp = new PdfPCell(new Paragraph(data.get(i).get("V2007")+"", fontChinese12));
tab.addCell(cell_temp);
cell_temp = new PdfPCell(new Paragraph(data.get(i).get("V2008")+"", fontChinese12));
tab.addCell(cell_temp);
cell_temp = new PdfPCell(new Paragraph(data.get(i).get("V2999")+"", fontChinese12));
tab.addCell(cell_temp);
cell_temp = new PdfPCell(new Paragraph(data.get(i).get("V9999")+"", fontChinese12));
tab.addCell(cell_temp);
if(data.get(i).get("IS_EVALUATING")=="10041002"){
cell_temp = new PdfPCell(new Paragraph("否", fontChinese12));
tab.addCell(cell_temp);
}else{
cell_temp = new PdfPCell(new Paragraph("是", fontChinese12));
tab.addCell(cell_temp);
}
cell_temp = new PdfPCell(new Paragraph(data.get(i).get("CANCEL_REASON")+"", fontChinese12));
tab.addCell(cell_temp);
}
}
return tab;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
private List<Map<String, Object>> tabData(){
String DEPT_NAME=CommonUtils.checkNull(reqUtil.getString("DEPT_NAME"));//区域
String DEALER_ID=CommonUtils.checkNull(reqUtil.getString("DEALER_ID"));//店代码
String DEALER_NAME=CommonUtils.checkNull(reqUtil.getString("DEALER_NAME"));//店简称
String year = CommonUtils.checkNull(reqUtil.getString("year"));//年度
String monthBegin = CommonUtils.checkNull(reqUtil.getString("monthBegin"));//月份
Map<String, String> passMap = new HashMap<String, String>();
passMap.put("DEPT_NAME", DEPT_NAME);
passMap.put("DEALER_ID", DEALER_ID);
passMap.put("year", year);
passMap.put("DEALER_NAME", DEALER_NAME);
passMap.put("monthBegin", monthBegin);
PageResult<Map<String, Object>> ps = dao.assessmentRangeSearch(passMap, Constant.PAGE_SIZE_ALL, 1);
List<Map<String, Object>> records = ps.getRecords();
return records;
}
//水印
public class Watermark extends PdfPageEventHelper {
Font FONT = new Font("",24, Font.BOLD, new GrayColor(0.75f));
private String waterCont;//水印内容
public Watermark() {
}
public Watermark(String waterCont) {
this.waterCont = waterCont;
}
@Override
public void onEndPage(PdfWriter writer, Document document) {
for(int i=0 ; i<20; i++) {
for(int j=0; j<28; j++) {
ColumnText.showTextAligned(writer.getDirectContentUnder(),
Element.ALIGN_CENTER,
new Phrase(this.waterCont == null ? "HELLO WORLD" : this.waterCont, FONT),
(50.5f+i*180),
(40.0f+j*130),
writer.getPageNumber() % 2 == 1 ? 45 : -45);
}
}
}
}
- JAVA导出pdf实例
一.直接导出成PDF Java代码 1. import java.io.FileNotFoundException; 2. import java.io.FileOutputStream; 3. ...
- java导出pdf功能记录
这几天已在做处理导出pdf文件的功能,摸索了几天总算可以了.记录下这几天遇到的问题. 1.网上基本都是基于Itext5和Itext7来处理的.我最终是在Itext5上成功了,itext7应该是模板出问 ...
- Java导出Pdf格式表单
前言 作为开发人员,工作中难免会遇到复杂表单的导出,接下来介绍一种通过Java利用模板便捷导出Pdf表单的方式 模拟需求 需求:按照下面格式导出pdf格式的学生成绩单 准备工作 Excel软件 ...
- Java导出pdf文件数据
提示:导出pdf文件,需要3个jar包iText-2.1.5.jar,iTextAsian.jar,iText-rtf-2.1.4.jar. public boolean outputPdfJhsy( ...
- 一次java导出pdf的经历
近期由于工作需要,需要将html代码导入到pdf中,经过了几种pdf的方案对比后发现IText是最简单和便捷的一种方式,于是乎采用了Itext. PDF生成 第一步:导入Maven依赖 <!-- ...
- java根据模板导出PDF详细教程
原文:https://blog.csdn.net/pengyufight/article/details/75305128 题记:由于业务的需要,需要根据模板定制pdf文档,经测试根据模板导出word ...
- java根据模板导出pdf
在网上看了一些Java生成pdf文件的,写的有点乱,有的不支持写入中文字体,有的不支持模板,有的只是随便把数据放里面生成文件,完全不考虑数据怎样放置的以及以后的维护性,想想还是自己总结一个完全版的导出 ...
- java利用itext导出pdf
项目中有一功能是导出历史记录,可以导出pdf和excel,这里先说导出pdf.在网上查可以用那些方式导出pdf,用itext比较多广泛. 导出pdf可以使用两种方式,一是可以根据已有的pdf模板,进行 ...
- java根据模板文件导出pdf
原文:https://www.cnblogs.com/wangpeng00700/p/8418594.html 在网上看了一些Java生成pdf文件的,写的有点乱,有的不支持写入中文字体,有的不支持模 ...
随机推荐
- 算法笔记--Splay && Link-Cut-Tree
Splay 参考:https://tiger0132.blog.luogu.org/slay-notes 普通模板: ; ], val[N], cnt[N], fa[N], sz[N], lazy[N ...
- Go语言学习之11 日志收集系统kafka库实战
本节主要内容: 1. 日志收集系统设计2. 日志客户端开发 1. 项目背景 a. 每个系统都有日志,当系统出现问题时,需要通过日志解决问题 b. 当系统机器比较少时,登陆到服务器上查看即可 ...
- NetSec2019 20165327 Exp0 Kali安装 Week1
NetSec2019 20165327 Exp0 Kali安装 Week1 一.下载并安装Kali和VMware kali在官网下载,VMware上学期已安装 安装如下步骤: 选典型: 选稍后安装操作 ...
- pgRouting新增扩展
环境依赖:postgresql cgal boost perl 环境变量: boost环境变量 CGAL环境变量 postgresql环境变量 1.新建C++ 空项目 2,添加common引用,更改配 ...
- layui 根据根据后台数据动态创建下拉框并同时默认选中
第一步 form表单里写好一个下拉框 <div class="layui-form-item"> <label class="layui-for ...
- laravel框架的注入
如果项目太大,最好采用注入的方式 首先在 根目录/app/ 下创建个service文件夹来 在控制器层可以调用 调用方法
- Mtlab:抛物型方程的交替方向隐格式(ADI)
tic; clear clc M=[,,,,]; N=M; :length(M) h=/M(p);% 这里定义空间步长等距 tau=/N(p); % 时间步长 x=:h:; y=:h:; t=:tau ...
- web前端bug积累
在将img转换为canvas时,在firefox中,如果img引用的svg使用了fill=(#id),此fill是无效的,可能导致整个转换失效,html2canvas.js也不行.chrome有效,其 ...
- strtol详解
文章装载自:http://blog.csdn.net/happylife1527/article/details/8441799,大家看到这篇文章想转载的请注明出处,尊重原作者劳动成果. 今天,在re ...
- [cf contest697] D - Puzzles
[cf contest697] D - Puzzles time limit per test 1 second memory limit per test 256 megabytes input s ...