liding
6 小时以前 2e378480e4920042ce57cc853ed33b35bcd580aa
fix(report): 解决Word报告生成中PNG图片压缩率问题
已修改1个文件
14 ■■■■■ 文件已修改
inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsReportServiceImpl.java 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsReportServiceImpl.java
@@ -43,6 +43,7 @@
import com.ruoyi.system.mapper.UserMapper;
import com.ruoyi.system.service.InformationNotificationService;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.openxml4j.util.ZipSecureFile;
import org.apache.poi.xwpf.usermodel.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@@ -524,7 +525,18 @@
    @Override
    public int wordInsertUrl(Map<String, Object> map, String url) {
        XWPFTemplate template = XWPFTemplate.compile(url).render(map);
        XWPFTemplate template;
        synchronized (ZipSecureFile.class) {
            double originalMinInflateRatio = ZipSecureFile.getMinInflateRatio();
            try {
                // 兼容报告中压缩率较高的纯色/透明 PNG,编译后立即恢复 POI 安全阈值。
                ZipSecureFile.setMinInflateRatio(0.001D);
                template = XWPFTemplate.compile(url);
            } finally {
                ZipSecureFile.setMinInflateRatio(originalMinInflateRatio);
            }
        }
        template.render(map);
        try {
            template.writeAndClose(Files.newOutputStream(Paths.get(url)));
        } catch (IOException e) {