|
@@ -1,15 +1,14 @@
|
|
|
package com.qmth.distributed.print.business.util;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.itextpdf.text.*;
|
|
|
import com.itextpdf.text.pdf.*;
|
|
|
import com.qmth.distributed.print.business.bean.dto.PdfPackageDto;
|
|
|
import com.qmth.distributed.print.business.bean.dto.PdfSignDto;
|
|
|
import com.qmth.distributed.print.business.service.PrintCommonService;
|
|
|
-import com.qmth.teachcloud.common.config.DictionaryConfig;
|
|
|
import com.qmth.teachcloud.common.contant.SpringContextHolder;
|
|
|
-import com.qmth.teachcloud.common.contant.SystemConstant;
|
|
|
+import com.qmth.teachcloud.common.enums.ClassifyEnum;
|
|
|
import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
|
|
|
-import com.qmth.teachcloud.common.enums.UploadFileEnum;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -18,7 +17,6 @@ import org.springframework.stereotype.Component;
|
|
|
import java.io.File;
|
|
|
import java.io.FileOutputStream;
|
|
|
import java.io.IOException;
|
|
|
-import java.time.LocalDateTime;
|
|
|
import java.util.List;
|
|
|
import java.util.*;
|
|
|
|
|
@@ -35,16 +33,18 @@ public class CreatePrintPdfUtil {
|
|
|
* @param pdfFillDto 签到表数据
|
|
|
* @param destFileName 文件名
|
|
|
*/
|
|
|
- public String createSignPdf(PdfSignDto pdfFillDto, String destFileName) throws Exception {
|
|
|
+ public File createSignPdf(PdfSignDto pdfFillDto, String destFileName) throws Exception {
|
|
|
|
|
|
// 1:建立Document对象实例
|
|
|
Document document = new Document(PageSize.A4, 36.0F, 36.0F, 40F, 36.0F);
|
|
|
// ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
|
File file = createFolder(destFileName);
|
|
|
+ FileOutputStream fos = null;
|
|
|
+ PdfWriter pdfWriter = null;
|
|
|
try {
|
|
|
// 2:建立一个PDF 写入器与document对象关联通过书写器(Writer)可以将文档写入到磁盘中
|
|
|
- FileOutputStream fos = new FileOutputStream(file);
|
|
|
- PdfWriter pdfWriter = PdfWriter.getInstance(document, fos);
|
|
|
+ fos = new FileOutputStream(file);
|
|
|
+ pdfWriter = PdfWriter.getInstance(document, fos);
|
|
|
|
|
|
//3、设置pdf页眉和页脚和水印
|
|
|
MyHeaderFooter headerFooter = new MyHeaderFooter();
|
|
@@ -60,9 +60,15 @@ public class CreatePrintPdfUtil {
|
|
|
|
|
|
} catch (DocumentException e) {
|
|
|
e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ if (fos != null) {
|
|
|
+ fos.close();
|
|
|
+ }
|
|
|
+ if (pdfWriter != null) {
|
|
|
+ pdfWriter.close();
|
|
|
+ }
|
|
|
}
|
|
|
- PrintCommonService dictionaryConfig = SpringContextHolder.getBean(PrintCommonService.class);
|
|
|
- return dictionaryConfig.uploadPdfFile(file);
|
|
|
+ return file;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -71,16 +77,18 @@ public class CreatePrintPdfUtil {
|
|
|
* @param pdfPackageDto 卷袋贴参数
|
|
|
* @param destFileName 保存文件名
|
|
|
*/
|
|
|
- public String createPackagePdf(PdfPackageDto pdfPackageDto, String destFileName) throws Exception {
|
|
|
+ public File createPackagePdf(PdfPackageDto pdfPackageDto, String destFileName) throws Exception {
|
|
|
|
|
|
// 1:建立Document对象实例
|
|
|
Document document = new Document(PageSize.A4, 36.0F, 36.0F, 40F, 36.0F);
|
|
|
// ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
|
File file = createFolder(destFileName);
|
|
|
+ FileOutputStream fos = null;
|
|
|
+ PdfWriter pdfWriter = null;
|
|
|
try {
|
|
|
// 2:建立一个PDF 写入器与document对象关联通过书写器(Writer)可以将文档写入到磁盘中
|
|
|
- FileOutputStream fos = new FileOutputStream(file);
|
|
|
- PdfWriter pdfWriter = PdfWriter.getInstance(document, fos);
|
|
|
+ fos = new FileOutputStream(file);
|
|
|
+ pdfWriter = PdfWriter.getInstance(document, fos);
|
|
|
// 3:打开文档
|
|
|
document.open();
|
|
|
//生成pdf
|
|
@@ -89,10 +97,16 @@ public class CreatePrintPdfUtil {
|
|
|
document.close();
|
|
|
} catch (DocumentException e) {
|
|
|
e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ if (fos != null) {
|
|
|
+ fos.close();
|
|
|
+ }
|
|
|
+ if (pdfWriter != null) {
|
|
|
+ pdfWriter.close();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- PrintCommonService dictionaryConfig = SpringContextHolder.getBean(PrintCommonService.class);
|
|
|
- return dictionaryConfig.uploadPdfFile(file);
|
|
|
+ return file;
|
|
|
}
|
|
|
|
|
|
/**
|