java hd seks_jodconverter-web/src/main/java/cn/keking/service/impl/AseKsReportServiceImpl.java · mes…

java hd seks_jodconverter-web/src/main/java/cn/keking/service/impl/AseKsReportServiceImpl.java · mes…packagecn.keking.service.impl;importcn.keking.hutool.StrUtil;importcn.keking.render.AseKsTableRenderPolicy;importcn.keking.render.CustomReplaceOptionalTextPictureRefRenderPolicy;importcn.keking.s…

大家好,又见面了,我是你们的朋友全栈君。

package cn.keking.service.impl;

import cn.keking.hutool.StrUtil;

import cn.keking.render.AseKsTableRenderPolicy;

import cn.keking.render.CustomReplaceOptionalTextPictureRefRenderPolicy;

import cn.keking.service.CapsReportService;

import cn.keking.utils.FileUtils;

import cn.keking.utils.OfficeToPdf;

import com.deepoove.poi.XWPFTemplate;

import com.deepoove.poi.config.Configure;

import org.apache.poi.xwpf.usermodel.XWPFDocument;

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;

import javax.imageio.ImageIO;

import java.awt.image.BufferedImage;

import java.io.File;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;

import java.math.BigDecimal;

import java.util.Map;

/**

* @program: filepreview

* @description: Caps AseKs报告

* @author: syngna

* @create: 2020-04-14 12:08

*/

@Service(“aseKs”)

public class AseKsReportServiceImpl implements CapsReportService {

@Autowired

private OfficeToPdf officeToPdf;

private static final Logger LOGGER = LoggerFactory.getLogger(AseKsReportServiceImpl.class);

@Override

public String processCapsReport(Map data, String picturePath, String templatePath, String outputPath) {

FileOutputStream out = null;

XWPFTemplate template = null;

String errorMsg = “”;

try {

// 计算图片比例

BufferedImage image = ImageIO.read(new FileInputStream(picturePath));

int width = image.getWidth();

int height = image.getHeight();

Configure configure = Configure.newBuilder()

.bind(“dynamic_table”, new AseKsTableRenderPolicy())

.referencePolicy(

new CustomReplaceOptionalTextPictureRefRenderPolicy(“picture-right”,

new FileInputStream(picturePath),

XWPFDocument.PICTURE_TYPE_PNG, BigDecimal.valueOf(width).divide(BigDecimal.valueOf(height), 6, BigDecimal.ROUND_HALF_UP)))

.build();

template = XWPFTemplate.compile(templatePath, configure).render(data);

FileUtils.createDirPath(outputPath.substring(0, outputPath.lastIndexOf(File.separator)));

out = new FileOutputStream(outputPath);

template.write(out);

officeToPdf.doc2PDF(outputPath, outputPath.substring(0, outputPath.lastIndexOf(“.”) + 1) + “pdf”);

} catch (Exception e) {

LOGGER.error(“”, e);

errorMsg += e.getMessage();

} finally {

try {

if (out != null) {

out.flush();

out.close();

}

if (template != null) {

template.close();

}

} catch (IOException e) {

LOGGER.error(“”, e);

}

}

return errorMsg;

}

}

一键复制

编辑

原始数据

按行查看

历史

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/156404.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • webstorm的永久激活码2021【2021.8最新】

    (webstorm的永久激活码2021)最近有小伙伴私信我,问我这边有没有免费的intellijIdea的激活码,然后我将全栈君台教程分享给他了。激活成功之后他一直表示感谢,哈哈~IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/100143.html…

    2022年3月26日
    253
  • python入门之实现一个简单的小游戏_python简单小游戏

    python入门之实现一个简单的小游戏_python简单小游戏首页资讯文章频道资源小组相亲登录注册首页资讯文章频道资源小组相亲首页资讯文章频道资源小组相亲登录注册登录注册首页最新文章经典回顾开发设计

    2022年8月1日
    13
  • MySQL数据库的性能优化总结

    MySQL数据库的性能优化总结

    2021年4月9日
    121
  • 321_MediaType Media Type 是什么

    321_MediaType Media Type 是什么MediaType是什么MediaType在网络协议的消息头里面叫做Content-Type使用两部分的标识符来确定一个类型所以我们用的时候其实就是为了表明我们传的东西是什么类型比如application/json:JSON格式的数据,在RFC4627中定义application/javascript:JavaScript,在RFC4329中定义但是…

    2022年5月9日
    82
  • java四舍五入(保留两位小数)[通俗易懂]

    java四舍五入(保留两位小数)[通俗易懂]1.最简单的方法:floata=123.4567f;这里的100就是2位小数点,如果要其它位,如4位,这里两个100改成10000floatb=(float)(Math.round(a*100))/100;doublef=111231.5585;BigDecimalb=newBigDecimal(f);doublef1=b.setScale(2,BigDecimal.ROUND_HALF_UP

    2022年5月16日
    44
  • webpack es6转es5_nodejs支持es6吗

    webpack es6转es5_nodejs支持es6吗万恶的IE遗臭万年仍然需要填坑ie标准对html/css甚至js的规范简直相差甚远,所以,一般要解决的兼容问题很大一部分是为了解决ie的不兼容,虽然目前流行的ES6语法及规范将IE的考虑抛弃掉,默认放弃对IE的治疗,但是IE的兼容仍然是个问题!即使IE的使用率已经不到1%的市场占比。我们使用着舒服的ES6规范但是为IE又很头疼怎么办呢?Webpack开发了非常厉害的打包转换功能:转ES5!…

    2022年9月25日
    3

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号