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) {