From 6cd5fefaf5f5f87572765b7d32cfa644541275cd Mon Sep 17 00:00:00 2001 From: wzp <2040239371@qq.com> Date: 星期三, 16 七月 2025 11:36:50 +0800 Subject: [PATCH] fix:修复docker不能正常清理的问题。设置60s超时时间 --- src/main/java/com/ots/project/tool/PdfUtil.java | 43 ++++++++++++++++++++++++++++++++++++++----- 1 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/ots/project/tool/PdfUtil.java b/src/main/java/com/ots/project/tool/PdfUtil.java index 607bb46..20f9b63 100644 --- a/src/main/java/com/ots/project/tool/PdfUtil.java +++ b/src/main/java/com/ots/project/tool/PdfUtil.java @@ -27,23 +27,55 @@ FontSettings.getDefaultInstance().setFontsSources(fontSourceBases); } +// public static void convertPDF(String input) { +// try { +// registerWord(); +// setFont(); +// Document pres = null; +// //鎵嬪姩鏇挎崲杈撳嚭pdf鍚嶇О +// String output = input.replaceAll(".docx", ".pdf"); +// long old = System.currentTimeMillis(); +// FileInputStream fileInput = new FileInputStream(input); +// pres = new Document(fileInput); +// FileOutputStream out = new FileOutputStream(new File(output)); +// pres.save(out, SaveFormat.PDF); +// out.close(); +// long now = System.currentTimeMillis(); +// log.info("銆愯浆鎹€�慸oc杞琾df鑰楁椂锛歿}绉�", ((now - old) / 1000.0)); +// } catch (Exception e) { +// e.printStackTrace(); +// } +// } + public static void convertPDF(String input) { + FileInputStream fileInput = null; + FileOutputStream out = null; + Document pres = null; try { registerWord(); setFont(); - Document pres = null; - //鎵嬪姩鏇挎崲杈撳嚭pdf鍚嶇О String output = input.replaceAll(".docx", ".pdf"); long old = System.currentTimeMillis(); - FileInputStream fileInput = new FileInputStream(input); + + fileInput = new FileInputStream(input); pres = new Document(fileInput); - FileOutputStream out = new FileOutputStream(new File(output)); + + out = new FileOutputStream(output); pres.save(out, SaveFormat.PDF); - out.close(); + long now = System.currentTimeMillis(); log.info("銆愯浆鎹€�慸oc杞琾df鑰楁椂锛歿}绉�", ((now - old) / 1000.0)); } catch (Exception e) { e.printStackTrace(); + } finally { + // 纭繚璧勬簮閲婃斁 + if (pres != null) pres = null; // 鍏抽敭锛氶噴鏀綝ocument鍘熺敓璧勬簮 + if (fileInput != null) { + try { fileInput.close(); } catch (IOException e) { /* ignore */ } + } + if (out != null) { + try { out.close(); } catch (IOException e) { /* ignore */ } + } } } @@ -52,6 +84,7 @@ * @param profile * @param docx2pdfPath * @param fileName + * 杩欎釜鏈夋椂鍊檇ocker杞寲浼氬崱姝伙紝2025.7.15鎷熼噰鐢╬dfDockerUtil鏂版柟娉曞鐞� */ public static void dockerConvertPDF(String profile,String docx2pdfPath,String fileName){ try { -- Gitblit v1.9.1