dows 文档转pdf 下载

@RequestMapping(“printIndexNew”)
public void toPage(String id,HttpServletResponse response) {
Notification notification = notificationService.getOne(id);
String type = notification.getType();// 小天使 或天使阳光
Map<String, Object> map = new HashMap<String, Object>();
map.put("KaTeX parse error: Expected '}', got 'EOF' at end of input: … map.put("{referenceNumber}", notification.getReferenceNumber());// 告知书档案号
} else {
map.put("KaTeX parse error: Expected 'EOF', got '}' at position 57: …告知书档案号 }̲ map.pu…{guardianName}", notification.getGuardianName());// 监护人名称
map.put(" c h i l d N a m e " , n o t i f i c a t i o n . g e t C h i l d N a m e ( ) ) ; / / 患 儿 名 字 m a p . p u t ( " {childName}", notification.getChildName());// 患儿名字 map.put(" childName",notification.getChildName());//map.put("{mobilePhone}", notification.getMobilePhone());// 手机
map.put(" f i x e d P h o n e " , n o t i f i c a t i o n . g e t F i x e d P h o n e ( ) ) ; / / 固 定 电 话 m a p . p u t ( " {fixedPhone}", notification.getFixedPhone());// 固定电话 map.put(" fixedPhone",notification.getFixedPhone());//map.put("{totalMoney}", notification.getTotalMoney() == null?"":notification.getTotalMoney().toString());// 总费用
if (null != notification.getReimbursementSpent() && null != notification.getOtherReimbursementSpent()) {
map.put("KaTeX parse error: Expected 'EOF', got '}' at position 282: … 报销总费用 }̲ map.pu…{selfPayment}", notification.getSelfPayment() == null ? “”:notification.getSelfPayment().toString());// 自付费用天使阳光
map.put(" a c c o u n t N a m e " , n o t i f i c a t i o n . g e t A c c o u n t N a m e ( ) ) ; / / 账 户 户 名 m a p . p u t ( " {accountName}", notification.getAccountName());// 账户户名 map.put(" accountName",notification.getAccountName());//map.put("{bankDeposit}", notification.getBankDeposit());// 开户行
map.put(" c a r d N u m b e r " , n o t i f i c a t i o n . g e t C a r d N u m b e r ( ) ) ; / / 卡 号 m a p . p u t ( " {cardNumber}", notification.getCardNumber());// 卡号 map.put(" cardNumber",notification.getCardNumber());//map.put("{hospital}", notification.getHospital());// 医院
map.put("KaTeX parse error: Expected '}', got 'EOF' at end of input: … map.put("{province}", projectRegion.getName().toString());
} else {
map.put("KaTeX parse error: Expected 'EOF', got '}' at position 30: …北京市"); }̲ if (nu…{passingAppraisalTime}",
DateUtils.formatDate(notification.getPassingAppraisalTime(), “yyyy年MM月dd日”));// 通过评审时间天使阳光
}
if (null != notification.getCreateTime()) {
map.put("KaTeX parse error: Expected 'EOF', got '}' at position 154: …月)天使阳光 }̲ if (nu…{operationTime}", DateUtils.formatDate(notification.getOperationTime(), “yyyy年MM月dd日”));// 手术时间天使阳光
}
map.put("${date}", DateUtils.formatDate(new Date(), “yyyy年MM月dd日”));// 下面角落日期
try {
String path = “”;
String fileName = “”;
// 下载模板分为待完善和已完善两大类(已下发就可以下载,此时模板只需要写患儿。时间等几个字段)
if (StringUtils.equals(notification.getStatus(), ChestConst.notification.NOTIFICATION_DAIWANSHANG)) {// 待完善
if (StringUtils.equals(type, ChestConst.chestAidType.XTS)) {// 小天使
fileName = new String(
(DateUtils.formatDate(new Date(), “yyMMddHHmmssSS”) + “小天使告知书”).getBytes(“UTF-8”),
“UTF-8”);
if (StringUtils.equals(notification.getApplicationType(),
ChestConst.notification.APPLICATION_TYPE)) {// 资助单
path = DNOTIFICATION_XTS_GUARDIAN;
} else {// 追加单
path = DNOTIFICATION_XTS_GUARDIAN_ADD;
}
} else {// 天使阳光
String cooperationType = notification.getCooperationType();
fileName = new String(
(DateUtils.formatDate(new Date(), “yyMMddHHmmssSS”) + “天使阳光告知书”).getBytes(“UTF-8”),
“UTF-8”);
if (StringUtils.equals(cooperationType, ChestConst.notification.COOPERATION_PROVINCE)) {// 省级单位
path = DNOTIFICATION_TSYG_GUARDIAN;
} else {// 定点医院 对于天使阳光且申请人为定点医院的 模板上不需要写 账户户名、开户行、卡号
path = DNOTIFICATION_TSYG_HOSPITAL;
}
}
} else {
if (StringUtils.equals(type, ChestConst.chestAidType.XTS)) {// 小天使
fileName = new String(
(DateUtils.formatDate(new Date(), “yyMMddHHmmssSS”) + “小天使告知书”).getBytes(“UTF-8”),
“UTF-8”);
if (StringUtils.equals(notification.getApplicationType(),
ChestConst.notification.APPLICATION_TYPE)) {// 资助单
path = NOTIFICATION_XTS_GUARDIAN;
} else {// 追加单
path = NOTIFICATION_XTS_GUARDIAN_ADD;
}
} else {// 天使阳光
String cooperationType = notification.getCooperationType();
fileName = new String(
(DateUtils.formatDate(new Date(), “yyMMddHHmmssSS”) + “天使阳光告知书”).getBytes(“UTF-8”),
“UTF-8”);
if (StringUtils.equals(cooperationType, ChestConst.notification.COOPERATION_PROVINCE)) {// 省级单位
path = NOTIFICATION_TSYG_GUARDIAN;
} else {// 定点医院 对于天使阳光且申请人为定点医院的 模板上不需要写 账户户名、开户行、卡号
path = NOTIFICATION_TSYG_HOSPITAL;
}
}
}
XwpfTUtil xwpfTUtil = new XwpfTUtil();

        XWPFDocument doc;
        InputStream is;
        String url = OssUtils.getUrl("upload/default/20210630195807BraxmMTExICgyKQ==.docx");

// is = getClass().getClassLoader().getResourceAsStream(url);
is = getFileInputStream(“http://crcf-gims.oss-cn-beijing.aliyuncs.com/upload/default/20210701091958OE7mjMTEy.docx?Expires=1625106007&OSSAccessKeyId=LTAIsDPVZNIEL8lY&Signature=IiMIyRwB5Q3kUAxXCGAsO6qnGVE%3D”);
// finally
// {
// urlConnection.disconnect();
// }

        //is = new FileInputStream("http://crcf-gims.oss-cn-beijing.aliyuncs.com/upload/default/20210628194345whVEo5paw5bu6IE1pY3Jvc29mdCBXb3JkIOaWh%2BahoyAoMik%3D.docx?Expires=1624884225&OSSAccessKeyId=LTAIsDPVZNIEL8lY&Signature=S70IokVAHqIlJFGc2%2BoUQeO46UQ%3D");
        //is = getClass().getClassLoader().getResourceAsStream(fileNameInResource);
        doc = new XWPFDocument(is);
 
        xwpfTUtil.replaceInPara(doc, map);
        //替换表格里面的变量
        xwpfTUtil.replaceInTable(doc, map);

// OutputStream os = response.getOutputStream();
// response.setContentType(“application/vnd.ms-excel”);
// response.setHeader(“Content-disposition”,“attachment;filename=”+fileName+".docx");
// doc.write(os);

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        doc.write(out);
        out.close();
        doc.close();
        byte[] xwpfDocumentBytes = out.toByteArray();
        
        
        FileOutputStream fop = null;
		File file2;
		file2 = new File("D:/"+fileName+".docx");
		fop = new FileOutputStream(file2);
		fop.write(xwpfDocumentBytes);
		fop.flush();
		fop.close();



		Word2PdfAsposeUtil.doc2pdf("D:\\"+fileName+".docx", "D:\\"+fileName+".pdf");
		File file3;
		file3 = new File("D:/"+fileName+".pdf");



		// 下载本地文件
	    // 读到流中
	    InputStream inStream = new FileInputStream("D:\\"+fileName+".pdf");// 文件的存放路径
	    // 设置输出的格式
	    response.reset();
	    response.setContentType("bin");
	    response.addHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\""+".pdf");
	    // 循环取出流中的数据
	    byte[] b = new byte[100];
	    int len;
	    try {
	      while ((len = inStream.read(b)) > 0)
	        response.getOutputStream().write(b, 0, len);
	      inStream.close();
	    } catch (IOException e) {
	      e.printStackTrace();
	    }
	    file2.delete();
	    file3.delete();

// xwpfTUtil.close(os);
// xwpfTUtil.close(is);
//
// os.flush();
// os.close();
} catch (Exception e) {
logger.error(e.getMessage());
e.printStackTrace();
}
}

/*读取网络文件*/
public static InputStream getFileInputStream(String path) {
    URL url = null;
    try {
        url = new URL(path);
        HttpURLConnection conn = (HttpURLConnection)url.openConnection();
        //设置超时间为3秒
        conn.setConnectTimeout(30*1000);
        //防止屏蔽程序抓取而返回403错误
        conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
        //得到输入流
        return conn.getInputStream();
    } catch (Exception e) {
        logger.error("读取网络文件异常:"+path);
    }
    return null;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值