后台代码

//出货清单
@RequestMapping(params="getBusinessOutDetail")
public void getBusinessOutDetail(HttpServletRequest req,HttpServletResponse response,String id,String codes) throws IOException {
String impTypess = req.getParameter("impTypess");//1、打印 2、预览 3、打印并预览
if("1".equals(impTypess)){
response.setHeader("Expires", "0");
response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode("收货清单.pdf" , "UTF-8"));
response.setHeader("Pragma", "public");
response.setContentType("application/pdf");
}
List<BusinessExpressEntity> expList = new ArrayList<>();
StringBuilder code = new StringBuilder("");
String productAllName = "";
String[] arr = codes.split(",");
for (String s : arr) {
BusinessExpressEntity express = systemService.findByProperty(BusinessExpressEntity.class, "shipmentLabelcode",s).get(0);
expList.add(express);
code.append("'" + s + "',");
productAllName += express.getProductName() + ",";
} String sql = " SELECT e.id,e.business_serveinvoicecode,e.consignee_country,e.product_name,e.business_pieces,e.business_grossweight,e.business_customervolumnweight,e.cargotype_code,group_concat(i.invoice_name SEPARATOR ';' ) as content,SUM(s.total_price) as totalPrice from business_express e \n" +
"LEFT JOIN business_invoice i on i.business_id = e.id\n" +
" LEFT JOIN wms_expenses_payment s on s.business_id = e.id \n" +
" LEFT JOIN business_shipment a on a.id = e.shipment_id \n" +
" where a.shipment_labelcode in ("+code.substring(0,code.length()-1).toString()+") and e.bpm_status!=0 GROUP BY e.id "; RowMapper<BusinessPdfDTO> rowMapper = new BeanPropertyRowMapper<BusinessPdfDTO>(BusinessPdfDTO.class);
List<BusinessPdfDTO> list = jdbcTemplate.query(sql, rowMapper); String typeSql = "SELECT * from t_s_type where typegroupid in (SELECT id from t_s_typegroup where typegroupcode= 'cargo')";
List<Map<String, Object>> typeList = jdbcTemplate.queryForList(typeSql);
HashMap typeMap = new HashMap<String, String>();
for (Map<String,Object> temp : typeList) {
typeMap.put(temp.get("typecode").toString(), temp.get("typename").toString());
} PdfFont font = PdfFontFactory.createFont("STSong-Light", "UniGB-UCS2-H",true); PdfDocument pdf = new PdfDocument(new PdfWriter(response.getOutputStream()));
Document document = new Document(pdf);
document.add(new Paragraph("出货交接清单").setVerticalAlignment(VerticalAlignment.MIDDLE).setTextAlignment(TextAlignment.CENTER).setFont(font).setFontSize(14));
for (BusinessExpressEntity express : expList) {
document.add(new Paragraph("出货信息:"+express.getShipmentLabelcode()+" "+DateUtils.date2Str(new Date(),DateUtils.time_sdf)+" "+express.getCustomerName()).setVerticalAlignment(VerticalAlignment.MIDDLE).setTextAlignment(TextAlignment.LEFT).setFont(font).setFontSize(12));
} Table table = new Table(new float[]{30,70,70,70,70,70,70,70,70,70});
table.addCell(new Cell().add(new Paragraph("序号")).setBorder(com.itextpdf.layout.borders.Border.NO_BORDER).setFont(font).setFontSize(9));
table.addCell(new Cell().add(new Paragraph("转单号")).setBorder(com.itextpdf.layout.borders.Border.NO_BORDER).setFont(font).setFontSize(9));
table.addCell(new Cell().add(new Paragraph("产品名称")).setBorder(com.itextpdf.layout.borders.Border.NO_BORDER).setFont(font).setFontSize(9));
table.addCell(new Cell().add(new Paragraph("件数")).setBorder(com.itextpdf.layout.borders.Border.NO_BORDER).setFont(font).setFontSize(9));
table.addCell(new Cell().add(new Paragraph("类型")).setBorder(com.itextpdf.layout.borders.Border.NO_BORDER).setFont(font).setFontSize(9));
table.addCell(new Cell().add(new Paragraph("国家")).setBorder(com.itextpdf.layout.borders.Border.NO_BORDER).setFont(font).setFontSize(9));
table.addCell(new Cell().add(new Paragraph("实重")).setBorder(com.itextpdf.layout.borders.Border.NO_BORDER).setFont(font).setFontSize(9));
table.addCell(new Cell().add(new Paragraph("体积重")).setBorder(com.itextpdf.layout.borders.Border.NO_BORDER).setFont(font).setFontSize(9));
//table.addCell(new Cell().add(new Paragraph("应收费用")).setBorder(com.itextpdf.layout.borders.Border.NO_BORDER).setFont(font).setFontSize(9));
table.addCell(new Cell().add(new Paragraph("备注")).setBorder(com.itextpdf.layout.borders.Border.NO_BORDER).setFont(font).setFontSize(9)); //统计包裹
int bg = 0;
//统计文件
int wj = 0;
double weight = 0;
double price = 0; for (int i=0;i<list.size();i++) {
table.addCell(new Cell().add(new Paragraph((i+1)+"")).setBorder(com.itextpdf.layout.borders.Border.NO_BORDER).setFont(font).setFontSize(9));
table.addCell(new Cell().add(new Paragraph(list.get(i).getBusinessServeinvoicecode())).setBorder(com.itextpdf.layout.borders.Border.NO_BORDER).setFont(font).setFontSize(9));
table.addCell(new Cell().add(new Paragraph(list.get(i).getProductName())).setBorder(com.itextpdf.layout.borders.Border.NO_BORDER).setFont(font).setFontSize(9));
table.addCell(new Cell().add(new Paragraph(list.get(i).getBusinessPieces()+"")).setBorder(com.itextpdf.layout.borders.Border.NO_BORDER).setFont(font).setFontSize(9));
if (typeMap.containsKey(list.get(i).getCargotypeCode())) {
table.addCell(new Cell().add(new Paragraph(typeMap.get(list.get(i).getCargotypeCode()).toString())).setBorder(com.itextpdf.layout.borders.Border.NO_BORDER).setFont(font).setFontSize(9));
} else {
table.addCell(new Cell().add(new Paragraph("")).setBorder(com.itextpdf.layout.borders.Border.NO_BORDER).setFont(font).setFontSize(9));
}
table.addCell(new Cell().add(new Paragraph(list.get(i).getConsigneeCountry())).setBorder(com.itextpdf.layout.borders.Border.NO_BORDER).setFont(font).setFontSize(9));
table.addCell(new Cell().add(new Paragraph(list.get(i).getBusinessGrossweight()==null?"": DecimalUtil.subData(list.get(i).getBusinessGrossweight()+""))).setBorder(com.itextpdf.layout.borders.Border.NO_BORDER).setFont(font).setFontSize(9));
table.addCell(new Cell().add(new Paragraph(list.get(i).getBusinessCustomervolumnweight()==null? "":list.get(i).getBusinessCustomervolumnweight()+"")).setBorder(com.itextpdf.layout.borders.Border.NO_BORDER).setFont(font).setFontSize(9));
//table.addCell(new Cell().add(new Paragraph(list.get(i).getTotalPrice()==null? "":list.get(i).getTotalPrice())).setBorder(com.itextpdf.layout.borders.Border.NO_BORDER).setFont(font).setFontSize(9));
table.addCell(new Cell().add(new Paragraph("配货:"+list.get(i).getContent())).setBorder(com.itextpdf.layout.borders.Border.NO_BORDER).setFont(font).setFontSize(9)); if("P".equals(list.get(i).getCargotypeCode())){
bg++;
}
if("D".equals(list.get(i).getCargotypeCode())){
wj++;
}
if (list.get(i).getBusinessGrossweight() != null) {
weight += java.lang.Double.parseDouble(list.get(i).getBusinessGrossweight().toString());
}
if (list.get(i).getTotalPrice() != null) {
price += java.lang.Double.parseDouble(list.get(i).getTotalPrice().toString());
} } document.add(table); document.add(new Paragraph("合计 总票数:"+list.size()+" 总实重:"+String.format("%.2f", weight)+" 总费用:"+price).setFont(font).setFontSize(9));
document.add(new Paragraph("包裹:"+bg+" 文件:"+wj).setFont(font).setFontSize(9).setMarginTop(-3));
// document.add(new Paragraph(express.getProductName()+" "+list.size()+" 票").setFont(font).setFontSize(9).setMarginTop(-8));
document.add(new Paragraph(productAllName.substring(0,productAllName.length()-1)+" "+list.size()+" 票").setFont(font).setFontSize(9).setMarginTop(-8)); document.add(new Paragraph("请仔细阅读后确认签字:").setFont(font).setFontSize(9).setMaxHeight(15).setMarginTop(-3));
document.add(new Paragraph("快件交接清单上显示的目的地国家仅供参考,正式录单时会再次确认,最终的目的地国家请以客户账单为准。如果发现快件").setFont(font).setFontSize(9).setMarginTop(-8).setMarginLeft(10));
document.add(new Paragraph("交接清单目的地国家有误,请立即告之快件签入人员或与负责贵司查询事务的客户专员联系,谢谢合作").setFont(font).setFontSize(9).setMarginTop(-8)); document.add(new Paragraph("收货公司签字: _________________ "+" "+"我司出货员: _________________").setFont(font).setFontSize(9).setMarginLeft(10)); document.close();
pdf.close(); }

前台代码:

function printQD() {
var rowsData = $('#businessArrivalList').datagrid('getSelections');
if(rowsData.length==0){
tip("请选择数据");
return false;
}else if(rowsData.length>1){
tip("只能选择一个数据");
return false;
}
var xueurl = "fileFormatController.do?getXbDetail_print&id=&codes=" + rowsData[0].arrivalLabelcode;
$.messager.defaults = { ok: "确定", cancel: "取消" };
const html = '<p id="p"><label for="r">请选择打印方式</label></p><p id="p">'
+ '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label for="r"><input type="radio" id="r" name="impTypess" value="1" checked>'
+ ' 直接打印</label>'
+ '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label for="r1"><input type="radio" id="r1" name="impTypess" value="2">'
+ ' 预览</label></p> </p>'
+ '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<label for="r2"><input type="radio" id="r2" name="impTypess" value="3" >'
+ ' 打印并预览</label></p> </p>'
$.messager.confirm("请选择打印方式", html, function (data) {
if (data) {
var impTypess = $("input[name='impTypess']:checked ").val();
xueurl+='&impTypess='+impTypess;
if(impTypess=='2'){//预览
window.open(xueurl);
}else if(impTypess=='3'){//预览并打印
window.open(xueurl);
window.location.href = 'fileFormatController.do?getXbDetail_print&id=&codes=' + rowsData[0].arrivalLabelcode+'&impTypess=1';
}else if(impTypess=='1'){//打印
window.location.href = 'fileFormatController.do?getXbDetail_print&id=&codes=' + rowsData[0].arrivalLabelcode+'&impTypess=1';
}
}
});
//window.location.href = "fileFormatController.do?getXbDetail_print&id=&codes=" + rowsData[0].arrivalLabelcode+"&ylFlag=0";
}

效果:

导出PDF 空白赋值备份的更多相关文章

  1. java根据模板导出pdf

    在网上看了一些Java生成pdf文件的,写的有点乱,有的不支持写入中文字体,有的不支持模板,有的只是随便把数据放里面生成文件,完全不考虑数据怎样放置的以及以后的维护性,想想还是自己总结一个完全版的导出 ...

  2. 史上最全的springboot导出pdf文件

    最近项目有一个导出报表文件的需求,我脑中闪过第一念头就是导出pdf(产品经理没有硬性规定导出excel还是pdf文件),于是赶紧上网查看相关的资料,直到踩了无数的坑把功能做出来了才知道其实导出exce ...

  3. 网页导出PDF文件

    转自-----出道诗人 var downPdf = document.getElementById("exportToPdf"); downPdf.onclick = functi ...

  4. java根据模板文件导出pdf

    原文:https://www.cnblogs.com/wangpeng00700/p/8418594.html 在网上看了一些Java生成pdf文件的,写的有点乱,有的不支持写入中文字体,有的不支持模 ...

  5. js_网页导出pdf文件

    打印当前页面,一开始我认为是需要输出pdf的,后来了解的需求是能够打印就可以了.需求既然都研究了,记录下. 更好的打印方式,window.print();会弹出打印对话框,打印的是window.doc ...

  6. JSP页面导出PDF格式文件

    JSP页面导出PDF格式文件基本在前端页面可以全部完成 <script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/ ...

  7. java动态导出PDF(利用itext)

    项目基于ssm框架,使用itext动态导出pdf文件: 1.引入两个jar包:itextpdf-5.5.5.jar.itext-asian-5.2.0.jar 说明: 1.itextpdf-5.5.5 ...

  8. HTML页面导出PDF——高清版

    需要做一个导出PDF的功能,网上找有很多,但是一般导出来的都是比较模糊的那种,下面这个是高清版的,导出的PDF都是几M,跟正常手动导出的差不多,很清晰. 首先用到的JS有: <script ty ...

  9. vue项目中导出PDF的两种方式

    参考大家导出的方式,基本上是如下两种: 1.使用 html2Canvas + jsPDF 导出PDF, 这种方式什么都好,就是下载的pdf太模糊了.对要求好的pdf这种方式真是不行啊! 2.调用浏览器 ...

  10. React项目实现导出PDF的功能

    在做web项目中,有时候会遇到pdf导出的需求,现根据之前在公司的React项目中遇到的导出PDF需求,整理一个demo出来. 导出PDF需要用到两个依赖包:html2canvas.jspdf 1.安 ...

随机推荐

  1. Windows 10 企业版 LSTC 激活秘钥及方法

    Windows 10 企业版 LSTC 秘钥:M7XTQ-FN8P6-TTKYV-9D4CC-J462D 同时按下Win键+X,然后选择Windows PowerShell(管理员)按顺序输入下面的字 ...

  2. MySQL 版本号排序

    1.业务背景 版本检查接口返回版本号排序时出现如下图所示问题 普通的查询按数字值逐级比较,导致版本号高的排在了后面,这样版本检查根据版本号排序倒排取出来的不是最新的版本号,本文就此问题查询了诸多方法, ...

  3. IDEA新手使用教程【详解】

    IDEA是一款功能强悍.非常好用的Java开发工具,近几年编程开发人员对IDEA情有独钟. Intellij Idea使用技巧总结 1.如何设置通过鼠标滑轮改变编辑器字体大小 2.如何设置自动导包功能 ...

  4. navicat无法连接linux内的防火墙

    解决方法:开放mysql的端口(3306).然后重启防火墙.或者直接关闭防火墙.具体代码如下: firewall-cmd --zone=public --add-port=3306/tcp --per ...

  5. JZOJ 3304. Theresa与数据结构

    \(\text{Problem}\) 标准四维偏序 带修改(加和删除)和询问的三维空间正方体内部(包括边上)的点的数目 \(\text{Analysis}\) 打法很多,\(\text{cdq}\) ...

  6. Python常见面试题006 类方法、类实例方法、静态方法有何区别?

    006. Python中类方法.类实例方法.静态方法有何区别? 全部放一个里面篇幅过大了,就拆分成1个个发布 示例代码 class Human: def __init__(self, name): s ...

  7. Python批量读取HDF多波段栅格数据并绘制像元直方图

      本文介绍基于Python语言gdal模块,实现多波段HDF栅格图像文件的读取.处理与像元值可视化(直方图绘制)等操作.   另外,基于gdal等模块读取.tif格式栅格图层文件的方法可以查看Pyt ...

  8. Solon2 的应用生命周期

    Solon 框架的应用生命周期包括:一个初始化函数时机点 + 六个事件时机点 + 两个插件生命时机点 + 两个容器生命时机点(v2.2.0 版本的状态): 提醒: 启动过程完成后,项目才能正常运行(启 ...

  9. ElasticSearch 实现分词全文检索 - ES、Kibana、IK安装

    目录 ElasticSearch 实现分词全文检索 - 概述 ElasticSearch 实现分词全文检索 - ES.Kibana.IK安装 ElasticSearch 实现分词全文检索 - Rest ...

  10. c# 游戏设计:地图移动

    想实现一个小游戏,先做地图移动.步骤记录如下: 1.百度到一张大的迷宫地图,放在项目的debug目录下,备用. 2.创建一个winform项目,不添加任何界面元素. 3.添加数据成员如下: Pictu ...