From 7dd88fc5c0ec639f6cc748d102324a507c0c1863 Mon Sep 17 00:00:00 2001 From: hcy <314517173@qq.com> Date: Mon, 20 May 2024 22:58:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B0=B4=E5=8D=B0=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../batchExport/BatchExportServiceImpl.java | 12 ++++++------ src/main/java/com/emr/util/img2PdfUtil.java | 19 ++++++++++--------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/emr/service/batchExport/BatchExportServiceImpl.java b/src/main/java/com/emr/service/batchExport/BatchExportServiceImpl.java index acc833c..41f6a32 100644 --- a/src/main/java/com/emr/service/batchExport/BatchExportServiceImpl.java +++ b/src/main/java/com/emr/service/batchExport/BatchExportServiceImpl.java @@ -257,7 +257,7 @@ public class BatchExportServiceImpl implements BatchExportService { bis = new BufferedInputStream(new ByteArrayInputStream(file1)); //输出 int len = 0; - byte[] buf = new byte[1024 * 1024]; + byte[] buf = new byte[100 * 1024]; while ((len = bis.read(buf, 0, buf.length)) != -1) { bos.write(buf, 0, len); } @@ -383,22 +383,22 @@ public class BatchExportServiceImpl implements BatchExportService { e.printStackTrace(); return false; } finally { - try { + //try { if (writer != null) { writer.close(); } - if (fileOutputStream != null) { + /*if (fileOutputStream != null) { fileOutputStream.close(); } if (bos != null) { bos.flush(); bos.close(); - } + }*/ - } catch (IOException e) { + /*} catch (IOException e) { e.printStackTrace(); - } + }*/ } return true; } diff --git a/src/main/java/com/emr/util/img2PdfUtil.java b/src/main/java/com/emr/util/img2PdfUtil.java index 7f2e2bd..4e8aa11 100644 --- a/src/main/java/com/emr/util/img2PdfUtil.java +++ b/src/main/java/com/emr/util/img2PdfUtil.java @@ -468,8 +468,7 @@ public class img2PdfUtil { PdfStamper stamper = null; try { reader = new PdfReader(bos.toByteArray()); - // PDF总页数 - int total = reader.getNumberOfPages(); + bos.reset(); // 重置 bos,以便 PdfStamper 可以写入 // 加完水印的文件 if (null != response) { stamper = new PdfStamper(reader, response.getOutputStream()); @@ -482,7 +481,9 @@ public class img2PdfUtil { // 循环对每页插入水印 PdfContentByte content; PdfGState gs = new PdfGState(); - for (int i = 1; i < total; i++) { + // PDF总页数 + int total = reader.getNumberOfPages(); + for (int i = 1; i <= total; i++) { //upOrUnder = 1为在文本之上 if (upOrUnder == 1) { // 水印在之前文本之上 @@ -524,17 +525,17 @@ public class img2PdfUtil { // 底部水印 content.endText(); //第二水印 - //content.beginText(); + content.beginText(); //16进制颜色转color - //content.setColorFill(color); + content.setColorFill(color); // 设置字体及字号 - //content.setFontAndSize(font, textSize); + content.setFontAndSize(font, textSize); // 设置起始位置 - //content.setTextMatrix(textX, textY); + content.setTextMatrix(textX, textY); // 中间水印 - //content.showTextAligned(Element.ALIGN_LEFT, text, textX, textY, textRotation); + content.showTextAligned(Element.ALIGN_LEFT, text, textX, textY, textRotation); // 底部水印 - //content.endText(); + content.endText(); } } } catch (IOException | DocumentException e) {