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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Mysql使用到substring截取字符串[通俗易懂]

    Mysql使用到substring截取字符串[通俗易懂]mysql截取字符串的时候是从1开始的而不是从0开始的语法:substring(str,start,len)bz:*_*的形式例子:select* fromcost wheresubstring(bz,1,1)

    2022年5月21日
    38
  • 【转】C:经典技巧,不用临时变量,交换变量值

    【转】C:经典技巧,不用临时变量,交换变量值

    2021年8月15日
    49
  • 软件测试前景和发展方向

    软件测试前景和发展方向2019最热门的软件测试趋势毛哥(译)放眼全球,了解技术发展的边界和趋势,有助于组织和个人的发展及竞争力的提升,偶尔看到国外某网站的一篇文章,读来颇值得参考,简单翻译过来,分享一下。也许这篇文章会给你一份指南,让你快速成长与发展。如今,随着世界数字化,我们目睹了技术进步的巨大变化。2019年也将标志着技术和数字化转型的巨大变化,从而要求组织不断创新和重塑自我。#1)敏捷与D…

    2022年4月28日
    72
  • Android制作字符串表格String.xml转EXCEL工具

    Android制作字符串表格String.xml转EXCEL工具publicstaticListgetAllExternalSdcardPath(){ListPathList=newArrayList();StringfirstPath=Environment.getExternalStorageDirectory().getPath();Log.d(TAG,”getAllExter

    2022年8月22日
    8
  • pandas drop参数_pandas concat函数

    pandas drop参数_pandas concat函数pandas中dropna()参数详解DataFrame.dropna(axis=0,how=‘any’,thresh=None,subset=None,inplace=False)1.axis参数确定是否删除包含缺失值的行或列axis=0或axis=’index’删除含有缺失值的行,axis=1或axis=’columns’删除含有缺失值的列,importpandasaspdimportnumpyasnpdf=pd.DataFrame({“name”:[‘Alfr

    2022年9月18日
    2
  • 数据结构:数组和链表的区别(数组和链表的优缺点 & 数组和链表的适用场景)

    数据结构:数组和链表的区别(数组和链表的优缺点 & 数组和链表的适用场景)数组和链表是两种基本的数据结构,他们在内存存储上的表现不一样,所以也有各自的特点数组一、数组的特点1.在内存中,数组是一块连续的区域2.数组需要预留空间在使用前需要提前申请所占内存的大小,这样不知道需要多大的空间,就预先申请可能会浪费内存空间,即数组空间利用率低ps:数组的空间在编译阶段就需要进行确定,所以需要提前给出数组空…

    2022年6月29日
    35

发表回复

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

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