From 803a57c57eee91bea9bc57ce0f7c743089b87b8a Mon Sep 17 00:00:00 2001 From: hujl <123@qq.com> Date: Tue, 6 Apr 2021 16:43:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../emr/controller/inHospitalController.java | 506 +++++++++----- .../emr/dao/Archive_Detail_PictureMapper.java | 21 + .../java/com/emr/entity/Archive_Detail.java | 10 +- .../emr/entity/Archive_Detail_Picture.java | 113 ++++ .../com/emr/entity/Archive_Detail_Vo.java | 10 +- .../Archive_Detail_PictureService.java | 21 + .../Archive_Detail_PictureServiceImpl.java | 50 ++ src/main/java/com/emr/util/AddImgToPdf.java | 92 +++ src/main/java/com/emr/util/Main.java | 230 ++++++- .../java/com/emr/util/PrintToPdfUtil.java | 494 +++++++++++--- .../java/com/emr/util/pdfDelPageTest.java | 2 + .../resources/mapper/Archive_DetailMapper.xml | 23 +- .../mapper/Archive_Detail_PictureMapper.xml | 211 ++++++ .../views/beHospitaledDir/beHospList.jsp | 572 +++++++++++++--- .../WEB-INF/views/commitDir/commitList.jsp | 637 ++++++++++++++---- .../views/inHospitalDir/inHositalList.jsp | 605 +++++++++++++++-- .../views/lastVerifyDir/lastVerifyList.jsp | 555 ++++++++++++--- .../medicalOverdueDir/medicalOverdueList.jsp | 2 +- .../unfileMedicalDir/unfileMedicalList.jsp | 571 +++++++++++++--- 19 files changed, 3983 insertions(+), 742 deletions(-) create mode 100644 src/main/java/com/emr/dao/Archive_Detail_PictureMapper.java create mode 100644 src/main/java/com/emr/entity/Archive_Detail_Picture.java create mode 100644 src/main/java/com/emr/service/Archive_Detail_PictureService.java create mode 100644 src/main/java/com/emr/service/ipml/Archive_Detail_PictureServiceImpl.java create mode 100644 src/main/java/com/emr/util/AddImgToPdf.java create mode 100644 src/main/resources/mapper/Archive_Detail_PictureMapper.xml diff --git a/src/main/java/com/emr/controller/inHospitalController.java b/src/main/java/com/emr/controller/inHospitalController.java index dca22edf..6d5678b9 100644 --- a/src/main/java/com/emr/controller/inHospitalController.java +++ b/src/main/java/com/emr/controller/inHospitalController.java @@ -10,19 +10,16 @@ import com.emr.annotation.OptionalLog; import com.emr.entity.*; import com.emr.service.*; import com.emr.util.*; -import com.github.pagehelper.util.StringUtil; import com.itextpdf.text.pdf.PdfReader; import com.lowagie.text.DocumentException; import net.sf.json.JSONArray; import net.sf.json.JSONObject; -import org.apache.commons.io.FileUtils; import org.apache.ibatis.annotations.Param; import org.apache.shiro.SecurityUtils; import org.apache.shiro.session.Session; import org.apache.shiro.subject.Subject; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.PropertySource; import org.springframework.stereotype.Controller; import org.springframework.transaction.annotation.Transactional; import org.springframework.ui.Model; @@ -60,6 +57,9 @@ public class inHospitalController { @Autowired private Zd_AssortService zd_assortService; + @Autowired + private Archive_Detail_PictureService archiveDetailPictureService; + @Resource private LogService logService; @@ -75,6 +75,10 @@ public class inHospitalController { @Value("${pdfErrorUrl}") private String pdfErrorUrl; + + //@Value("${pdfDelPicUrl}") + //private String pdfDelPicUrl; + @RequestMapping(value = "/inHospitals") public String inHospitals(Model model) { return "inHospitalDir/inHositalList"; @@ -153,21 +157,32 @@ public class inHospitalController { if (file2.exists() && file2.isFile()) { file2.delete(); } + if(detail.getRecoverPdfPath()!=null &&detail.getRecoverPdfPath()!="") { + File file3 = new File(detail.getRecoverPdfPath()); + if (file3.exists() && file3.isFile()) { + file3.delete(); + } + } } } - int bol=archiveDetailService.delById(archiveDetail.getId()); + //http://127.0.0.1:8080/emr_medical_record/static/img/login.jpg + // 项目在容器中实际发布运行的根路径 + String realPath = request.getSession().getServletContext().getRealPath("/"); + // 设置存放图片文件的路径 + String pdfDelPicUrl = "static\\img\\delPicImg\\"; + int bol = archiveDetailService.delById(archiveDetail.getId()); //备份都删除 - if(bol==1){ - Archive_Detail archiveDetailV=new Archive_Detail(); - archiveDetailV.setMasterid(detail.getMasterid()); - archiveDetailV.setFlag("1"); - archiveDetailV.setAssortid(detail.getAssortid()); - archiveDetailV.setSource(detail.getSource()); - String oldPath=detail.getPdfPath(); - String newPath=oldPath.substring(0,oldPath.lastIndexOf("\\")+1); - String newName=oldPath.substring(oldPath.lastIndexOf("\\")+1,oldPath.length()); - archiveDetailV.setPdfPath(newPath+"%备份_"+newName); - archiveDetailService.delByClo(archiveDetailV); + if (bol == 1) { + Archive_Detail_Picture archiveDetailPicture = new Archive_Detail_Picture(); + archiveDetailPicture.setParentId(archiveDetail.getId()); + if (archiveDetail.getPdfPath() != null && archiveDetail.getPdfPath() != "") { + archiveDetailPicture.setMaxPicture("static\\img\\delPicImg\\" + archiveDetail.getPdfPath() + "\\" + archiveDetail.getPdfPath() + "_"); + } + archiveDetailPictureService.deleteByCol(archiveDetailPicture); + //删除图片 + //将之前文件删除 + File file = new File(realPath + pdfDelPicUrl + archiveDetail.getPdfPath() + "\\"); + PrintToPdfUtil.delete(file); } @@ -232,7 +247,7 @@ public class inHospitalController { } //2021-03-15更新优化 - private String GeneratePDFFileByAssortID(String masterId, String assortID, String realPath,String flag) throws Exception { + private String GeneratePDFFileByAssortID(String masterId, String assortID, String realPath, String flag) throws Exception { List pdfList = new ArrayList(); Archive_Detail archiveDetail = new Archive_Detail(); archiveDetail.setFlag(flag); @@ -243,30 +258,30 @@ public class inHospitalController { List errorPdfList = new ArrayList<>(); int size = 0; - if (arList == null || arList.size()==0) { + if (arList == null || arList.size() == 0) { return ""; } - for (int m = 0; m < arList.size(); m++) { - MergePDFItem mergePDFItem = new MergePDFItem(); - String str = arList.get(m).getPdfPath(); - if (str != "" && str != null) { - if (str.indexOf("..\\static\\img\\pdfFiles\\") != -1) { - str = str.split("pdfFiles")[1]; - str = realPath + "pdfFiles" + str; - } - if (!PrintToPdfUtil.checkPdfFile(str)) { - arList.get(m).setPdfPath(str); - errorPdfList.add(arList.get(m)); - } else { - mergePDFItem.setPdfPath(str); - mergePDFItem.setdObj(arList.get(m)); - pdfList.add(mergePDFItem); - } + for (int m = 0; m < arList.size(); m++) { + MergePDFItem mergePDFItem = new MergePDFItem(); + String str = arList.get(m).getPdfPath(); + if (str != "" && str != null) { + if (str.indexOf("..\\static\\img\\pdfFiles\\") != -1) { + str = str.split("pdfFiles")[1]; + str = realPath + "pdfFiles" + str; + } + if (!PrintToPdfUtil.checkPdfFile(str)) { + arList.get(m).setPdfPath(str); + errorPdfList.add(arList.get(m)); + } else { + mergePDFItem.setPdfPath(str); + mergePDFItem.setdObj(arList.get(m)); + pdfList.add(mergePDFItem); } } + } String pdfFileName = String.valueOf(System.currentTimeMillis()); - String pdfPath = autoPdfUrl.trim() + "/" + pdfFileName + ".pdf"; + String pdfPath = autoPdfUrl.trim() + "/" + pdfFileName + ".pdf"; if (pdfList.size() > 0) { //对所有地址的pdf进行合成 @@ -283,7 +298,6 @@ public class inHospitalController { } - /** * 根据病案号或类别或图片id获取图片列表,并生成PDF并返回pdf文件名 * @@ -296,7 +310,7 @@ public class inHospitalController { */ @ResponseBody @RequestMapping(value = "/getPdfToPdf") - public String getPdfToPdf(HttpServletResponse response, HttpServletRequest request, String imgStr, String masterId,String flag) throws Exception { + public String getPdfToPdf(HttpServletResponse response, HttpServletRequest request, String imgStr, String masterId, String flag) throws Exception { request.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8"); String result = ""; @@ -334,10 +348,9 @@ public class inHospitalController { } } - for (int i = zds.size()-1; i >=0 ; i--) { + for (int i = zds.size() - 1; i >= 0; i--) { String a = zds.get(i).getAssortId(); - if(imgList.indexOf(a)==-1) - { + if (imgList.indexOf(a) == -1) { zds.remove(i); } @@ -347,19 +360,17 @@ public class inHospitalController { for (int i = 0; i < zds.size(); i++) { String asordID = zds.get(i).getAssortId(); - String pdfA = GeneratePDFFileByAssortID(masterId, asordID, realPath,flag); - if(pdfA=="" || pdfA.length()==0) - { + String pdfA = GeneratePDFFileByAssortID(masterId, asordID, realPath, flag); + if (pdfA == "" || pdfA.length() == 0) { continue; } fileList.add(pdfA); } - if(fileList.size()==0) - { + if (fileList.size() == 0) { return ""; } - String pdfPath = autoPdfUrl.trim() + "/" + String.valueOf(System.currentTimeMillis()) + ".pdf"; + String pdfPath = autoPdfUrl.trim() + "/" + String.valueOf(System.currentTimeMillis()) + ".pdf"; PDFHelper.Append(fileList, pdfPath); //PrintToPdfUtil.mergePdfFiles(fileList, pdfPath); return pdfPath; @@ -524,11 +535,11 @@ public class inHospitalController { } if (pdfList.size() > 0) { //if (errorPdfList.size() != size) { - //对所有地址的pdf进行合成 - PrintToPdfUtil.mergePdfFiles(pdfList, pdfPath); - result = pdfPath; + //对所有地址的pdf进行合成 + PrintToPdfUtil.mergePdfFiles(pdfList, pdfPath); + result = pdfPath; //} else { - // result = ""; + // result = ""; //} if (errorPdfList.size() > 0) { ExportTxtPaper.exportTxtPaper(pdfErrorUrl, "不存在或损坏PDF文件列表" + pdfFile + ".txt", errorPdfList); @@ -589,36 +600,36 @@ public class inHospitalController { } String pdfPath = realPath + entity.getRelationId() + "\\" + entity.getAssortId() + "\\" + entity.getAssortId() + ".pdf"; - // if (msg.equals("文件未被操作!")) { - //将之前文件删除 - File file = new File(pdfPath); - if (file1.exists() && file1.isFile()) { - file1.delete(); - } - //重新生成pdf - //读取指定路径下的文件名和目录名 - List arr = new ArrayList(); - //arr.add(pathType); - //图片转PDF(病案号文件夹+类别文件夹) - if(arr.size()>0) { - msg = PrintToPdfUtil.toPdf(realPath + path2, pdfPath, arr); - } - //存在删除 - bol = emrPictureService.deleteById(emrPicture.getId()); - //判断图片是否存在如果不存在则删除类别PDF - Emr_Picture obj=new Emr_Picture(); + // if (msg.equals("文件未被操作!")) { + //将之前文件删除 + File file = new File(pdfPath); + if (file1.exists() && file1.isFile()) { + file1.delete(); + } + //重新生成pdf + //读取指定路径下的文件名和目录名 + List arr = new ArrayList(); + //arr.add(pathType); + //图片转PDF(病案号文件夹+类别文件夹) + if (arr.size() > 0) { + msg = PrintToPdfUtil.toPdf(realPath + path2, pdfPath, arr); + } + //存在删除 + bol = emrPictureService.deleteById(emrPicture.getId()); + //判断图片是否存在如果不存在则删除类别PDF + Emr_Picture obj = new Emr_Picture(); obj.setRelationId(entity.getRelationId()); obj.setAssortId(entity.getAssortId()); - List picL=emrPictureService.selectByClo(obj); - if(picL.size()==0){ - Archive_Detail detailObj=new Archive_Detail(); + List picL = emrPictureService.selectByClo(obj); + if (picL.size() == 0) { + Archive_Detail detailObj = new Archive_Detail(); detailObj.setMasterid(entity.getRelationId()); detailObj.setAssortid(entity.getAssortId()); - String pdfpaht= pictureUrl + "\\" + entity.getRelationId() + "\\" + entity.getAssortId() + "\\" + entity.getAssortId() + ".pdf"; + String pdfpaht = pictureUrl + "\\" + entity.getRelationId() + "\\" + entity.getAssortId() + "\\" + entity.getAssortId() + ".pdf"; detailObj.setPdfPath(pdfpaht); //该病案的类型无图片则删除该病案类型的PDF及删除PDF记录 - List detailsL= archiveDetailService.selectByColm(detailObj); - if(detailsL.size()>0) { + List detailsL = archiveDetailService.selectByColm(detailObj); + if (detailsL.size() > 0) { archiveDetailService.delById(detailsL.get(0).getId()); // 判断pdf是否存在,将之前文件删除 File file2 = new File(pdfpaht); @@ -628,18 +639,18 @@ public class inHospitalController { } } - // } + // } } } - // if (msg.equals("文件未被操作!")) { - if (bol == 1) { - msg = "删除成功!"; - } else { - msg = "删除失败!"; - } + // if (msg.equals("文件未被操作!")) { + if (bol == 1) { + msg = "删除成功!"; + } else { + msg = "删除失败!"; + } //}else{ - // msg="文件正被操作!"; - // } + // msg="文件正被操作!"; + // } return msg; } @@ -934,7 +945,7 @@ public class inHospitalController { List dirList = new ArrayList(); dirList.add(pathType.replace("\\", "")); try { - PrintToPdfUtil.image2pdf(realPath + path2,dirList); + PrintToPdfUtil.image2pdf(realPath + path2, dirList); } catch (DocumentException e) { e.printStackTrace(); } @@ -1122,7 +1133,6 @@ public class inHospitalController { String trueFileName = firstFile + fileName; // 设置存放图片文件的路径 path = realPath + "\\static\\img\\uploads\\" + trueFileName; - SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String nowTime = format1.format(new Date()); //将其路径及文件名类型以及参数保存图片相关信息到分段详细表 @@ -1130,7 +1140,6 @@ public class inHospitalController { entity.setMasterid(masterID); entity.setAssortid(assortID); entity.setUploaddatetime(nowTime); - entity.setPdfPath("../static/img/uploads/" + trueFileName); Archive_Detail detail = new Archive_Detail(); int bol = 0; @@ -1240,36 +1249,36 @@ public class inHospitalController { Archive_Detail detail = new Archive_Detail(); int bol = 0; //PDF文件操作 - if (!id.equals("")) { - entity.setId(id); - detail = archiveDetailService.selectByid(id); - if (detail != null) { - //判断类型是否变更 - if (assortID.equals(detail.getAssortid())) { - //相同 - } else { - //判断file是否为空 - if (file == null) { - if (detail.getPdfPath() != null) { - String newFileName = (detail.getPdfPath()).substring((detail.getPdfPath()).lastIndexOf("\\") + 1); - entity.setPdfPath(path.replace("\\\\", "\\") + newFileName); - //不同pdf转移在删除 - PrintToPdfUtil.copyFile(detail.getPdfPath(), entity.getPdfPath()); - } + if (!id.equals("")) { + entity.setId(id); + detail = archiveDetailService.selectByid(id); + if (detail != null) { + //判断类型是否变更 + if (assortID.equals(detail.getAssortid())) { + //相同 + } else { + //判断file是否为空 + if (file == null) { + if (detail.getPdfPath() != null) { + String newFileName = (detail.getPdfPath()).substring((detail.getPdfPath()).lastIndexOf("\\") + 1); + entity.setPdfPath(path.replace("\\\\", "\\") + newFileName); + //不同pdf转移在删除 + PrintToPdfUtil.copyFile(detail.getPdfPath(), entity.getPdfPath()); } } - //根据id修改记录 - bol = archiveDetailService.updateCloById(entity); - } + //根据id修改记录 + bol = archiveDetailService.updateCloById(entity); + + } + } else { + //插入记录 + if (file != null) { + bol = archiveDetailService.insertSel(entity); } else { - //插入记录 - if (file != null) { - bol = archiveDetailService.insertSel(entity); - } else { - result = "没有找到相对应的文件!"; - } + result = "没有找到相对应的文件!"; } + } if (file != null) { type = fileName.indexOf(".") != -1 ? fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length()) : null; @@ -1341,7 +1350,7 @@ public class inHospitalController { @RequestMapping("getImg2") - public void getImg2(HttpServletRequest request, HttpServletResponse response,String path)throws IOException { + public void getImg2(HttpServletRequest request, HttpServletResponse response, String path) throws IOException { FileInputStream fis = null; OutputStream os = null; try { @@ -1366,7 +1375,7 @@ public class inHospitalController { } @RequestMapping("insertLog") - public void insertLog(HttpServletRequest request, HttpServletResponse response,Emr_Log logBo)throws IOException { + public void insertLog(HttpServletRequest request, HttpServletResponse response, Emr_Log logBo) throws IOException { // 从session获取用户名 Subject currentUser = SecurityUtils.getSubject(); Session session = currentUser.getSession(); @@ -1378,19 +1387,19 @@ public class inHospitalController { logBo.setCreater(username); //日志实体对象 logBo.setSysFlag("EMR_Medical_Record"); - String idStr=logBo.getLogContent(); + String idStr = logBo.getLogContent(); logBo.setIp("10.10.01.1"); - if(idStr!=null &&idStr!=""){ - if(idStr.indexOf(",")!=-1){ - String[] idArr =idStr.split(","); + if (idStr != null && idStr != "") { + if (idStr.indexOf(",") != -1) { + String[] idArr = idStr.split(","); for (int i = 0; i < idArr.length; i++) { logBo.setLogTitle(idArr[i]); logBo.setLogContent("调用手动作废."); // 添加到数据库 logService.insert(logBo); } - }else{ + } else { logBo.setLogTitle(idStr); logBo.setLogContent("调用单手动作废."); // 添加到数据库 @@ -1402,63 +1411,240 @@ public class inHospitalController { @ResponseBody @RequestMapping(value = "/delPdfPage") - public int delPdfPage(HttpServletResponse response, HttpServletRequest request,Archive_Detail archiveDetail) throws Exception { + public int delPdfPage(HttpServletResponse response, HttpServletRequest request, Archive_Detail archiveDetail) throws Exception { request.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8"); + // 从session获取用户名 + Subject currentUser = SecurityUtils.getSubject(); + Session session = currentUser.getSession(); + String username = (String) session.getAttribute("userSession");//获取前面登录的用户名 SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat format2 = new SimpleDateFormat("yyyyMMddHHmmss"); String nowTime = format2.format(new Date()); - int pageNum=Integer.parseInt(archiveDetail.getTitle()); - int bol = 0; - if(pageNum==0){ - pageNum=1; - }else if(pageNum==1){ - pageNum=0; + int pageNum = Integer.parseInt(archiveDetail.getTitle()); + int pageNum2 = 0; + if (archiveDetail.getSys() != null && archiveDetail.getSys() != "") { + pageNum2 = Integer.parseInt(archiveDetail.getSys()); } - File file=new File(archiveDetail.getPdfPath()); + int bol = 1; + File file = new File(archiveDetail.getPdfPath()); + PdfReader pdfReader = new PdfReader(new FileInputStream(file)); int pages = pdfReader.getNumberOfPages(); + // 项目在容器中实际发布运行的根路径 + String realPath = request.getSession().getServletContext().getRealPath("/"); + // 设置存放图片文件的路径 + String pdfDelPicUrl = realPath + "static\\img\\delPicImg\\"; // System.out.println("pdf文件的总页数为:" + pages); - if(pages>=pageNum) { - if (file.exists()) { - //删除之前备份并作废记录 - String id=archiveDetail.getId(); - //查询记录 - Archive_Detail archiveDetailDel=archiveDetailService.selectByid(id); - //插入新作废记录 - archiveDetailDel.setTitle(archiveDetailDel.getTitle()+"_备份"+nowTime); - if(archiveDetailDel.getTitle().indexOf("_备份")!=-1){ - String oldName=archiveDetailDel.getTitle().split("_备份")[0]; - archiveDetailDel.setTitle(oldName+"_备份"+nowTime); - } - archiveDetailDel.setFlag("1"); - archiveDetailDel.setUploaddatetime(format1.format(new Date())); - //复制一份原有null的pdf文件 - String copyPdfName=nowTime+"备份_"+file.getName(); - if(file.getName().indexOf("备份_")!=-1){ - String oldName=file.getName().split("备份_")[1]; - copyPdfName=nowTime+"备份_"+oldName; + + if (pages != 1) { + if ((pages >= pageNum && pageNum2 == 0) || (pages > ((pageNum2 - pageNum) + 1) && (pageNum2 != 0 && pages >= pageNum2))) { + if (file.exists()) { + if (bol == 1) { + //判断是否有备份如果没有则备份pdf文件 + Archive_Detail archiveDetail2 = archiveDetailService.selectByid(archiveDetail.getId()); + if (archiveDetail2 != null) { + if (archiveDetail2.getRecoverPdfPath() == null|| archiveDetail2.getRecoverPdfPath() == "") { + //备份pdf文件复印并将记录保存 + String recoverPdfPath = archiveDetail2.getPdfPath().replace(file.getName(), "") + nowTime + ".pdf"; + archiveDetail2.setRecoverPdfPath(recoverPdfPath); + archiveDetailService.updateCloById(archiveDetail2); + //复印pdf备份 + PrintToPdfUtil.copyFile2(archiveDetail2.getPdfPath(), recoverPdfPath); + } + } + List arrL = new ArrayList(); + // bol = pdfDelPageTest.cutPdf(archiveDetail.getPdfPath(), archiveDetail.getPdfPath(), pageNum);//删除第n页 + String pdfPath = archiveDetail.getPdfPath(); + List> list = PrintToPdfUtil.pdfToImage(archiveDetail.getPdfPath(), pageNum, pageNum2, pdfDelPicUrl); + nowTime = format1.format(new Date()); + //删除pdf页码成功,保存记录到数据库删除图片表中 + Archive_Detail_Picture archiveDetailPicture = new Archive_Detail_Picture(); + archiveDetailPicture.setCreater(username); + archiveDetailPicture.setCreateTime(nowTime); + archiveDetailPicture.setUpdateTime(nowTime); + archiveDetailPicture.setUpdater(username); + archiveDetailPicture.setEffective(1); + archiveDetailPicture.setParentId(archiveDetail.getId()); + if (list.size() > 0) { + for (Map map : list) { + if (map.get("max_picture") != null && map.get("max_picture") != "") { + if (map.get("max_picture").indexOf("static") != -1) { + String[] maxPicArr = map.get("max_picture").trim().split("static"); + String maxPic = maxPicArr[1]; + archiveDetailPicture.setMaxPicture("static" + maxPic); + } + } + if (arrL.indexOf(archiveDetailPicture.getMaxPicture()) == -1) { + arrL.add(archiveDetailPicture.getMaxPicture()); + archiveDetailPicture.setPictureNumber(Integer.parseInt(map.get("picture_number"))); + archiveDetailPictureService.insertSelective(archiveDetailPicture); + } + } + + } else { + bol = 0; + } + } else { + //备份失败 + bol = 4; + } + } else { + //pdf文件不存在 + bol = 2; } - String copyPath=archiveDetail.getPdfPath().substring(0,archiveDetail.getPdfPath().lastIndexOf("\\")); - archiveDetailDel.setPdfPath(copyPath+"\\"+copyPdfName); - bol=archiveDetailService.insertSel(archiveDetailDel); - //保存旧版本文件 - PrintToPdfUtil.save(file, copyPdfName, copyPath); - if(bol==1) { - bol = pdfDelPageTest.cutPdf(archiveDetail.getPdfPath(), archiveDetail.getPdfPath(), pageNum);//删除第n页 - }else{ - //备份失败 - bol=4; + } else { + //删除页码大于总页数 + bol = 3; + } + } else { + bol = 5; + } + return bol; + } + + //@OptionalLog(methods = "查询相关的页码图片列表") + @ResponseBody + @RequestMapping(value = "/selDelPicList") + public List selDelPicList(HttpServletRequest request, HttpServletResponse response, Archive_Detail_Picture archiveDetailPicture) { + List list = archiveDetailPictureService.selectByCol(archiveDetailPicture); + return list; + } + + //@OptionalLog(methods = "删除所有页码图片") + @ResponseBody + @RequestMapping(value = "/delPageImgAll") + public int delPageImgAll(HttpServletRequest request, HttpServletResponse response, Archive_Detail_Picture archiveDetailPicture) { + int bol = 0; + String fileDirName = archiveDetailPicture.getMaxPicture(); + archiveDetailPicture.setMaxPicture(null); + bol = archiveDetailPictureService.deleteByCol(archiveDetailPicture); + if (bol == 1) { + // 项目在容器中实际发布运行的根路径 + String realPath = request.getSession().getServletContext().getRealPath("/"); + // 设置存放图片文件的路径 + String pdfDelPicUrl = "static\\img\\delPicImg\\"; + //将之前文件目录下图片删除 + File file = new File(realPath + pdfDelPicUrl + fileDirName + "\\"); + PrintToPdfUtil.delete(file); + } + + return bol; + } + + //@OptionalLog(methods = "删除单张页码图片") + @ResponseBody + @RequestMapping(value = "/delPageImg") + public int delPageImg(HttpServletRequest request, HttpServletResponse response, Archive_Detail_Picture archiveDetailPicture) { + int bol = 0; + bol = archiveDetailPictureService.deleteByCol(archiveDetailPicture); + if (bol == 1) { + // 项目在容器中实际发布运行的根路径 + String realPath = request.getSession().getServletContext().getRealPath("/"); + //将之前图片文件删除 + File file = new File(realPath + archiveDetailPicture.getMaxPicture()); + if (file.exists() && file.isFile()) { + file.delete(); + } + } + + return bol; + } + + //@OptionalLog(methods = "PDF文件添加页码") + @ResponseBody + @RequestMapping(value = "/addPdfPageBtn") + public int addPdfPageBtn(HttpServletRequest request, HttpServletResponse response, Archive_Detail_Picture archiveDetailPicture) { + String orgPdfPath = archiveDetailPicture.getMaxPicture(); + File file = new File(orgPdfPath); + SimpleDateFormat format2 = new SimpleDateFormat("yyyyMMddHHmmss"); + String nowTime = format2.format(new Date()); + String filePath = file.getAbsolutePath().replace(file.getName(), ""); + String fileName = nowTime + "_" + file.getName(); + filePath += fileName; + File file1 = new File(filePath); + file.renameTo(file1); + String result = PrintToPdfUtil.addPageNum(filePath, orgPdfPath); + if (result != "" && result != null) { + file1.deleteOnExit(); + } + return 1; + } + + //@OptionalLog(methods = "PDF文件还原页码") + @ResponseBody + @RequestMapping(value = "/returnPage") + public String returnPage(HttpServletRequest request, HttpServletResponse response, Archive_Detail_Picture archiveDetailPicture) throws Exception { + String result = ""; + int bol = 0; + // 模板文件路径 + String templatePath = (archiveDetailPicture.getMinPicture()); + // 生成的文件路径 + String targetPath = archiveDetailPicture.getMinPicture(); + String realPath = request.getSession().getServletContext().getRealPath("/"); + // 图片路径 + String imagePath = realPath + archiveDetailPicture.getMaxPicture(); + // 页数 + int pageNum = archiveDetailPicture.getPictureNumber(); + File file = new File(templatePath); + PdfReader pdfReader = new PdfReader(new FileInputStream(file)); + int pages = pdfReader.getNumberOfPages(); + if (pages >= 1) { + if ((pages) >= pageNum) { + if (file.exists() && file.isFile()) { + result = AddImgToPdf.addImgToPdf(templatePath, targetPath, imagePath, pageNum); + if (result != "文件不存在") { + archiveDetailPicture.setMaxPicture(null); + archiveDetailPicture.setMinPicture(null); + archiveDetailPicture.setPictureNumber(null); + //删除记录 + bol = archiveDetailPictureService.deleteByCol(archiveDetailPicture); + if (bol == 1) { + file.delete(); + } + result = "图片还原到" + pageNum + "页成功!"; + } else { + result = "图片还原失败!"; + } } } else { - //pdf文件不存在 - bol = 2; + result = "图片还原" + pageNum + "要小于等于" + pages + "!"; + } + } else { + result = "pdf文件无内容!"; + } + return result; + } + + @ResponseBody + @RequestMapping(value = "/returnPdfFile") + public String returnPdfFile(HttpServletRequest request, HttpServletResponse response, Archive_Detail archiveDetail) throws Exception { + String result=""; + //判断是否有备份如果没有则备份pdf文件 + archiveDetail = archiveDetailService.selectByid(archiveDetail.getId()); + if(archiveDetail!=null){ + if(archiveDetail.getPdfPath()!="" && archiveDetail.getPdfPath()!=null && archiveDetail.getRecoverPdfPath()!="" && archiveDetail.getRecoverPdfPath()!=null){ + PrintToPdfUtil.copyFile2(archiveDetail.getRecoverPdfPath(), archiveDetail.getPdfPath()); + //并删除图片记录 + Archive_Detail_Picture archiveDetailPicture=new Archive_Detail_Picture(); + archiveDetailPicture.setParentId(archiveDetail.getId()); + String fileDirName=archiveDetail.getPdfPath(); + fileDirName = fileDirName.substring(fileDirName.lastIndexOf("\\")+1).replace(".pdf",""); + int bol = archiveDetailPictureService.deleteByCol(archiveDetailPicture); + if (bol == 1) { + // 项目在容器中实际发布运行的根路径 + String realPath = request.getSession().getServletContext().getRealPath("/"); + // 设置存放图片文件的路径 + String pdfDelPicUrl = "static\\img\\delPicImg\\"; + //将之前文件目录下图片删除 + File file = new File(realPath + pdfDelPicUrl + fileDirName + "\\"); + PrintToPdfUtil.delete(file); + } + }else{ + result="暂无备份pdf文件!"; } - }else{ - //删除页码大于总页数 - bol=3; } - return bol; + return result; } } diff --git a/src/main/java/com/emr/dao/Archive_Detail_PictureMapper.java b/src/main/java/com/emr/dao/Archive_Detail_PictureMapper.java new file mode 100644 index 00000000..a9b4c048 --- /dev/null +++ b/src/main/java/com/emr/dao/Archive_Detail_PictureMapper.java @@ -0,0 +1,21 @@ +package com.emr.dao; + +import com.emr.entity.Archive_Detail_Picture; + +import java.util.List; + +public interface Archive_Detail_PictureMapper { + int deleteByCol(Archive_Detail_Picture record); + + int insert(Archive_Detail_Picture record); + + int insertSelective(Archive_Detail_Picture record); + + Archive_Detail_Picture selectByPrimaryKey(Integer id); + + List selectByCol(Archive_Detail_Picture record); + + int updateByPrimaryKeySelective(Archive_Detail_Picture record); + + int updateByPrimaryKey(Archive_Detail_Picture record); +} \ No newline at end of file diff --git a/src/main/java/com/emr/entity/Archive_Detail.java b/src/main/java/com/emr/entity/Archive_Detail.java index 10b87931..6963d07f 100644 --- a/src/main/java/com/emr/entity/Archive_Detail.java +++ b/src/main/java/com/emr/entity/Archive_Detail.java @@ -17,7 +17,7 @@ public class Archive_Detail { private String flag; private String sys; private int pageNumber; - private String delAssortID; + private String recoverPdfPath; public Archive_Detail() { } @@ -110,11 +110,11 @@ public class Archive_Detail { this.pageNumber = pageNumber; } - public String getDelAssortID() { - return delAssortID; + public String getRecoverPdfPath() { + return recoverPdfPath; } - public void setDelAssortID(String delAssortID) { - this.delAssortID = delAssortID; + public void setRecoverPdfPath(String recoverPdfPath) { + this.recoverPdfPath = recoverPdfPath; } } diff --git a/src/main/java/com/emr/entity/Archive_Detail_Picture.java b/src/main/java/com/emr/entity/Archive_Detail_Picture.java new file mode 100644 index 00000000..9fe06548 --- /dev/null +++ b/src/main/java/com/emr/entity/Archive_Detail_Picture.java @@ -0,0 +1,113 @@ +package com.emr.entity; + +public class Archive_Detail_Picture { + private Integer id; + + private String parentId; + + private String minPicture; + + private String maxPicture; + + private Integer pictureNumber; + + private Integer effective; + + private String creater; + + private String createTime; + + private String updater; + + private String updateTime; + + private String remark; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getParentId() { + return parentId; + } + + public void setParentId(String parentId) { + this.parentId = parentId == null ? null : parentId.trim(); + } + + public String getMinPicture() { + return minPicture; + } + + public void setMinPicture(String minPicture) { + this.minPicture = minPicture == null ? null : minPicture.trim(); + } + + public String getMaxPicture() { + return maxPicture; + } + + public void setMaxPicture(String maxPicture) { + this.maxPicture = maxPicture == null ? null : maxPicture.trim(); + } + + public Integer getPictureNumber() { + return pictureNumber; + } + + public void setPictureNumber(Integer pictureNumber) { + this.pictureNumber = pictureNumber; + } + + public Integer getEffective() { + return effective; + } + + public void setEffective(Integer effective) { + this.effective = effective; + } + + public String getCreater() { + return creater; + } + + public void setCreater(String creater) { + this.creater = creater == null ? null : creater.trim(); + } + + public String getCreateTime() { + return createTime; + } + + public void setCreateTime(String createTime) { + this.createTime = createTime == null ? null : createTime.trim(); + } + + public String getUpdater() { + return updater; + } + + public void setUpdater(String updater) { + this.updater = updater == null ? null : updater.trim(); + } + + public String getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(String updateTime) { + this.updateTime = updateTime == null ? null : updateTime.trim(); + } + + public String getRemark() { + return remark; + } + + public void setRemark(String remark) { + this.remark = remark == null ? null : remark.trim(); + } +} \ No newline at end of file diff --git a/src/main/java/com/emr/entity/Archive_Detail_Vo.java b/src/main/java/com/emr/entity/Archive_Detail_Vo.java index 350336c0..b64f78e0 100644 --- a/src/main/java/com/emr/entity/Archive_Detail_Vo.java +++ b/src/main/java/com/emr/entity/Archive_Detail_Vo.java @@ -24,7 +24,7 @@ public class Archive_Detail_Vo { private String patientId; private String scanPage; private int pageNum; - private String delAssortID; + private String recoverPdfPath; private String archivestate; private String cmtDoctorDate; private String cmtNurseDate; @@ -177,12 +177,8 @@ public class Archive_Detail_Vo { this.pageNum = pageNum; } - public String getDelAssortID() { - return delAssortID; - } - - public void setDelAssortID(String delAssortID) { - this.delAssortID = delAssortID; + public void setPageNum(int pageNum) { + this.pageNum = pageNum; } public String getArchivestate() { diff --git a/src/main/java/com/emr/service/Archive_Detail_PictureService.java b/src/main/java/com/emr/service/Archive_Detail_PictureService.java new file mode 100644 index 00000000..70483b36 --- /dev/null +++ b/src/main/java/com/emr/service/Archive_Detail_PictureService.java @@ -0,0 +1,21 @@ +package com.emr.service; + +import com.emr.entity.Archive_Detail_Picture; + +import java.util.List; + +public interface Archive_Detail_PictureService { + int deleteByCol(Archive_Detail_Picture record); + + int insert(Archive_Detail_Picture record); + + int insertSelective(Archive_Detail_Picture record); + + Archive_Detail_Picture selectByPrimaryKey(Integer id); + + List selectByCol(Archive_Detail_Picture record); + + int updateByPrimaryKeySelective(Archive_Detail_Picture record); + + int updateByPrimaryKey(Archive_Detail_Picture record); +} diff --git a/src/main/java/com/emr/service/ipml/Archive_Detail_PictureServiceImpl.java b/src/main/java/com/emr/service/ipml/Archive_Detail_PictureServiceImpl.java new file mode 100644 index 00000000..12424825 --- /dev/null +++ b/src/main/java/com/emr/service/ipml/Archive_Detail_PictureServiceImpl.java @@ -0,0 +1,50 @@ +package com.emr.service.ipml; + +import com.emr.dao.Archive_Detail_PictureMapper; +import com.emr.entity.Archive_Detail_Picture; +import com.emr.service.Archive_Detail_PictureService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class Archive_Detail_PictureServiceImpl implements Archive_Detail_PictureService { + + @Autowired + private Archive_Detail_PictureMapper archiveDetailPictureMapper; + @Override + public int deleteByCol(Archive_Detail_Picture record) { + return archiveDetailPictureMapper.deleteByCol(record); + } + + @Override + public int insert(Archive_Detail_Picture record) { + return archiveDetailPictureMapper.insert(record); + } + + @Override + public int insertSelective(Archive_Detail_Picture record) { + return archiveDetailPictureMapper.insertSelective(record); + } + + @Override + public Archive_Detail_Picture selectByPrimaryKey(Integer id) { + return archiveDetailPictureMapper.selectByPrimaryKey(id); + } + + @Override + public List selectByCol(Archive_Detail_Picture record) { + return archiveDetailPictureMapper.selectByCol(record); + } + + @Override + public int updateByPrimaryKeySelective(Archive_Detail_Picture record) { + return archiveDetailPictureMapper.updateByPrimaryKeySelective(record); + } + + @Override + public int updateByPrimaryKey(Archive_Detail_Picture record) { + return archiveDetailPictureMapper.updateByPrimaryKey(record); + } +} diff --git a/src/main/java/com/emr/util/AddImgToPdf.java b/src/main/java/com/emr/util/AddImgToPdf.java new file mode 100644 index 00000000..b566f81c --- /dev/null +++ b/src/main/java/com/emr/util/AddImgToPdf.java @@ -0,0 +1,92 @@ +package com.emr.util; + +import com.itextpdf.text.*; +import com.itextpdf.text.pdf.*; +import org.apache.pdfbox.pdmodel.PDPage; +import org.apache.pdfbox.pdmodel.PDPageContentStream; +import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject; + +import java.io.*; +import java.text.SimpleDateFormat; +import java.util.Date; + +public class AddImgToPdf { + final private static float A4_weight = 595;//标准A4的宽 + final private static float A4_height = 842;//标准A4的高 + public static String addImgToPdf(String templatePath,String targetPath,String imagePath,int pageNum) { + String result=""; + try{ + // 读取模板文件 + InputStream input = new FileInputStream(new File(templatePath)); + PdfReader reader = new PdfReader(input); + PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(targetPath)); + //读图片 + Image image = Image.getInstance(imagePath); + // 获取操作的页面 + PdfContentByte under =null; + if(pageNum==0) { + stamper.insertPage(1 , reader.getPageSizeWithRotation(1));//新增空白页 + // 获取操作的页面 + under = stamper.getOverContent(1); + }else{ + stamper.insertPage(pageNum + 1, reader.getPageSizeWithRotation(pageNum));//新增空白页 + // 获取操作的页面 + under = stamper.getOverContent(pageNum+1); + } + + /*处理图片缩放比例*/ + float w = image.getWidth(); + float h = image.getHeight(); + float percent = 0; + if ((w > A4_weight) && (h < A4_height)) { + percent = (A4_weight * 100) / w; + } else if ((w < A4_weight) && (h > A4_height)) { + percent = (A4_height * 100) / h; + } else if ((w > A4_weight) && (h > A4_height)) { + percent = (A4_weight * 100) / w; + h = (h * percent) / 100; + if (h > A4_height) { + percent = (A4_height * 100) / h; + } + } + // 读取图片流 + image.setAlignment(com.lowagie.text.Image.ALIGN_CENTER); + if (percent != 100) { + image.scaleAbsolute(A4_weight, A4_height); + } else { + image.scalePercent(percent); + } //这里是写死要插入的坐标 + float x = 0; + float y = 0; + // 添加图片 + image.setAbsolutePosition(x, y); + under.addImage(image); + stamper.close(); + reader.close(); + //System.out.println("操作完成"); + }catch (Exception e){ + e.printStackTrace(); + } + return result; + } + + + + public static void main(String[] args) throws Exception { + //F:\old\EMR_Medical_Record\target\emr_medical_record-1.0-SNAPSHOT\static\img\delPicImg\202104011839513 + // 模板文件路径 + String templatePath = "C:\\Users\\Administrator\\Desktop\\test\\delPicImg\\331.pdf"; + + // 生成的文件路径 + String targetPath = "C:\\Users\\Administrator\\Desktop\\test\\delPicImg\\332.pdf"; + // 图片路径 + String imagePath = "C:\\Users\\Administrator\\Desktop\\test\\delPicImg\\2.jpg"; + // 页数 + int pageNum=1; + System.out.println(templatePath); + + //String result=AddImgToPdf( templatePath, targetPath, imagePath,pageNum); + PrintToPdfUtil.addPageNum(templatePath, targetPath); + + } +} diff --git a/src/main/java/com/emr/util/Main.java b/src/main/java/com/emr/util/Main.java index a909625c..93563a68 100644 --- a/src/main/java/com/emr/util/Main.java +++ b/src/main/java/com/emr/util/Main.java @@ -1,35 +1,45 @@ package com.emr.util; -import com.lowagie.text.BadElementException; +import com.itextpdf.text.Rectangle; +import com.itextpdf.text.pdf.*; import com.lowagie.text.Document; import com.lowagie.text.DocumentException; import com.lowagie.text.Image; import com.lowagie.text.pdf.PdfWriter; -import org.apache.http.entity.ContentType; -import org.springframework.mock.web.MockMultipartFile; -import org.springframework.web.multipart.MultipartFile; +import org.apache.pdfbox.pdmodel.PDDocument; +import org.apache.pdfbox.pdmodel.PDPage; +import org.apache.pdfbox.pdmodel.PDPageContentStream; +import org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException; +import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject; +import org.apache.pdfbox.rendering.ImageType; +import org.apache.pdfbox.rendering.PDFRenderer; import javax.imageio.ImageIO; import java.awt.image.BufferedImage; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.List; +import java.io.*; +import java.text.SimpleDateFormat; +import java.util.*; public class Main { final private static float A4_weight = 595;//标准A4的宽 final private static float A4_height = 842;//标准A4的高 + + /** + * 经过测试,dpi为96,100,105,120,150,200中, + * 120,150,200显示效果较为清晰,体积稳定,dpi越高图片体积越大 + */ + public static final float DEFAULT_DPI = 200; + public static final String DEFAULT_FORMAT = "jpg"; + /*** * @param picturePath * 图片地址 */ - private static void createPic( String picturePath,Document document) { + private static void createPic(String picturePath, Document document) { try { - File file=new File(picturePath); + File file = new File(picturePath); File[] files = file.listFiles(); - Image img =null; + Image img = null; if (files.length > 0) { for (File file1 : files) { @@ -55,18 +65,18 @@ public class Main { // 读取图片流 img.setAlignment(com.lowagie.text.Image.ALIGN_CENTER); - if(percent != 100){ - img.scaleAbsolute(A4_weight,A4_height); - }else{ + if (percent != 100) { + img.scaleAbsolute(A4_weight, A4_height); + } else { img.scalePercent(percent); } document.open(); document.add(img); - }else if(file1.isDirectory()){ + } else if (file1.isDirectory()) { //是文件夹迭代 System.out.println(file1.getAbsolutePath()); - createPic(file1.getAbsolutePath(),document); + createPic(file1.getAbsolutePath(), document); } } } @@ -75,38 +85,172 @@ public class Main { } } - public static void image2pdf(String text,List dirList) throws DocumentException, IOException { + public static void image2pdf(String text, List dirList) throws DocumentException, IOException { /* Document document = new Document(); OutputStream os = new FileOutputStream(new File(pdf)); PdfWriter.getInstance(document, os); document.open();*/ //循环类别 - if(dirList.size()>0){ - for(int i=0;i 0) { + for (int i = 0; i < dirList.size(); i++) { Document document = new Document(); - OutputStream os = new FileOutputStream(new File(text+dirList.get(i)+"//"+dirList.get(i)+".pdf")); + OutputStream os = new FileOutputStream(new File(text + dirList.get(i) + "//" + dirList.get(i) + ".pdf")); PdfWriter.getInstance(document, os); - // document.open(); - File file=new File(text+dirList.get(i)); + // document.open(); + File file = new File(text + dirList.get(i)); File[] files = file.listFiles(); if (files.length > 0) { // 循环获取图片文件夹内的图片,全部 - createPic(text+dirList.get(i),document); + createPic(text + dirList.get(i), document); + + } + + + } + } + } + + /** + * 将PDF转化为图片 + * (使用 pdfbox) + * + * @param pdfPath PDF对象 + * @param page_end 要转换的页码,发票一般是一页,取第一页 + * @param imgPath 图片保存路径 + * @return + */ + public static List pdfToImage(String pdfPath, int page_start, int page_end, String imgPath) { + String result = ""; + List list = new ArrayList(); + Map map = null; + File file = new File(pdfPath); + if (file.exists()) { + SimpleDateFormat format2 = new SimpleDateFormat("yyyyMMddHHmmss"); + String nowTime = format2.format(new Date()); + String filePath = file.getName().substring(0, file.getName().lastIndexOf(".")); + + try { + PDDocument doc = PDDocument.load(file); + PDFRenderer renderer = new PDFRenderer(doc); + int pageCount = doc.getNumberOfPages(); + + String fileName = ""; + String oleFileName = file.getName().substring(0, file.getName().lastIndexOf(".")); + for (int i = pageCount; i > 0; i--) { + if ((i <= page_end && i >= (page_start)) || (page_end == 0 && i == page_start)) { + map = new HashMap<>(); + BufferedImage image = renderer.renderImageWithDPI(i - 1, 296); + // BufferedImage image = renderer.renderImage(i, 2.5f); + File file2 = new File(imgPath + oleFileName + "\\"); //此目录保存缩小后的关键图 + if (!file2.exists()) { + //如果要创建的多级目录不存在才需要创建。 + file2.mkdirs(); + } + fileName = oleFileName + "_" + nowTime + "_" + (i) + "." + DEFAULT_FORMAT; + ImageIO.write(image, DEFAULT_FORMAT, new File(imgPath + oleFileName + "\\" + fileName)); + map.put("max_picture", imgPath + oleFileName + "\\" + fileName); + map.put("picture_number", i + ""); + list.add(map); + if (i == 1) { + doc.removePage(0); + + } else { + doc.removePage(i - 1); + } + } } + doc.save(pdfPath); + + } catch (IOException e) { + e.printStackTrace(); + } + } else { + result = "文件不存在!"; + } + + return list; + } + public static void delete(File file) { + if (!file.exists()) return; + if (file.isFile() || file.list() == null) { + file.delete(); + // System.out.println("删除了"+file.getName()); + } else { + File[] files = file.listFiles(); + for (File a : files) { + delete(a); } + file.delete(); + // System.out.println("删除了"+file.getName()); } + } + + /** + * 插入单张图片 + * + * @param inputPdfPath 要操作的pdf路径 C:\\Users\\aaa\\Desktop\\20181011114615447qp.pdf + * @param outputPdfPath 输出的pdf路径 + * @param imgPath 添加的图片路径 E:\\code\\qrcode.png + * @param pageNum 页数位置 + * @return + */ + public static int insertImgToPdf(String inputPdfPath, String outputPdfPath, String imgPath,int pageNum) { + File file = new File(inputPdfPath); + File file2 = new File(outputPdfPath); + int bol=1; + if (file.exists()) { + try { + PDDocument doc = PDDocument.load(file); + PDDocument doc2 = PDDocument.load(file2); + PDFRenderer renderer = new PDFRenderer(doc); + int pageCount = doc.getNumberOfPages(); + + + doc.save(outputPdfPath); + for (int i = pageCount-1; i >= 0; i--) { + PDPage myPage = doc.getPage(i); + Image image = Image.getInstance(imgPath); + PDImageXObject pdImage = PDImageXObject.createFromFile(imgPath, doc2); + + int iw = pdImage.getWidth(); + int ih = pdImage.getHeight(); + float offset = 20f; + try (PDPageContentStream cont = new PDPageContentStream(doc2, myPage)) { + cont.drawImage(pdImage, offset, offset, iw, ih); + + } + + if (i==pageNum || i==(pageNum-1)) { + BufferedImage image2 = renderer.renderImageWithDPI(i - 1, 296); + + + + } + } + doc2.save(outputPdfPath); + } catch (Exception e) { + e.printStackTrace(); + } + } + + return bol; + } + + + + public static void main(String[] args) throws IOException { //读取指定路径下的文件名和目录名 - List dirList = new ArrayList(); + /* List dirList = new ArrayList(); dirList.add("3"); - dirList.add("17"); - /* try { - image2pdf("C:\\Users\\Administrator\\Desktop\\test\\uploadImage\\11111111111133333\\",dirList); + //dirList.add("17"); + try { + image2pdf("C:\\Users\\Administrator\\Desktop\\文档\\",dirList); } catch (DocumentException e) { e.printStackTrace(); }*/ @@ -141,5 +285,33 @@ public class Main { e.printStackTrace(); }*/ + + //删除pdf页码保存图片 + String pdfPath="C:\\Users\\Administrator\\Desktop\\test\\delPicImg\\331.pdf"; + int page_start=1; + int page_end=3; + String imgPath="C:\\Users\\Administrator\\Desktop\\test\\delPicImg\\"; + List list=pdfToImage(pdfPath,page_start,page_end,imgPath); + System.out.println(list.toString()); + + //删除文件夹的和所有文件 + //File file = new File("C:\\Users\\Administrator\\Desktop\\test\\delPicImg\\202103311721593"); + //delete(file); + // 模板文件路径 + String templatePath = "C:\\Users\\Administrator\\Desktop\\test\\delPicImg\\3.pdf"; + // 生成的文件路径 + String targetPath = "C:\\Users\\Administrator\\Desktop\\test\\delPicImg\\target.pdf"; + // 图片路径 + String fieldName = "C:\\Users\\Administrator\\Desktop\\test\\delPicImg\\2.jpg"; + // 页数 + int pageNum=0; + String imagePath = "C:\\Users\\Administrator\\Desktop\\test\\delPicImg\\2.jpg"; + //insertImgToPdf(templatePath, targetPath, fieldName,pageNum); + + + } + + + } diff --git a/src/main/java/com/emr/util/PrintToPdfUtil.java b/src/main/java/com/emr/util/PrintToPdfUtil.java index 3c36be49..57b652ed 100644 --- a/src/main/java/com/emr/util/PrintToPdfUtil.java +++ b/src/main/java/com/emr/util/PrintToPdfUtil.java @@ -7,8 +7,11 @@ package com.emr.util; import com.emr.entity.Archive_Detail; +import com.emr.entity.Archive_Detail_Picture; import com.emr.entity.MergePDFItem; import com.github.pagehelper.Page; +import com.itextpdf.text.Element; +import com.itextpdf.text.Phrase; import com.lowagie.text.Document; import com.lowagie.text.DocumentException; import com.lowagie.text.Image; @@ -18,21 +21,24 @@ import com.lowagie.text.rtf.RtfWriter2; import com.sun.image.codec.jpeg.JPEGCodec; import com.sun.image.codec.jpeg.JPEGImageEncoder; import com.sun.javafx.css.Size; +import org.apache.axis.client.Call; +import org.apache.axis.client.Service; import org.apache.commons.io.FileUtils; import org.apache.pdfbox.io.MemoryUsageSetting; import org.apache.pdfbox.multipdf.PDFMergerUtility; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.common.PDRectangle; +import org.apache.pdfbox.rendering.PDFRenderer; import javax.imageio.ImageIO; +import javax.xml.namespace.QName; import java.awt.*; import java.awt.image.BufferedImage; import java.io.*; -import java.util.ArrayList; -import java.util.HashMap; +import java.text.SimpleDateFormat; +import java.util.*; import java.util.List; -import java.util.Map; /** * 将多张图片合并转为PDF;需要用到iTextpdf包, @@ -42,6 +48,12 @@ import java.util.Map; public class PrintToPdfUtil { final private static float A4_weight = 595;//标准A4的宽 final private static float A4_height = 842;//标准A4的高 + /** + * 经过测试,dpi为96,100,105,120,150,200中, + * 120,150,200显示效果较为清晰,体积稳定,dpi越高图片体积越大 + */ + public static final float DEFAULT_DPI = 200; + public static final String DEFAULT_FORMAT = "jpg"; public static boolean forceDelete(File file) { boolean result = file.delete(); @@ -168,25 +180,25 @@ public class PrintToPdfUtil { } doc.open(); - if(msg.equals("文件未被操作!")){ - // OutputStream fos = new FileOutputStream(pdfPath); - // 输入流 - OutputStream fos = new FileOutputStream(new File(pdfPath)); + if(msg.equals("文件未被操作!")){ + // OutputStream fos = new FileOutputStream(pdfPath); + // 输入流 + OutputStream fos = new FileOutputStream(new File(pdfPath)); // 获取图片文件夹对象 File file = new File(imageFolderPath); - // 写入PDF文档 - PdfWriter.getInstance(doc, fos); - //imageFolderPath = file.getAbsolutePath() + "\\"; - imgFun(imageFolderPath, file, dirList, doc); - - try { - if(fos!=null) { - fos.close(); - } - } catch (IOException e) { - e.printStackTrace(); - } + // 写入PDF文档 + PdfWriter.getInstance(doc, fos); + //imageFolderPath = file.getAbsolutePath() + "\\"; + imgFun(imageFolderPath, file, dirList, doc); + + try { + if(fos!=null) { + fos.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } } } catch (Exception e) { @@ -225,7 +237,7 @@ public class PrintToPdfUtil { if (file1.isDirectory()) { if (dirList != null && dirList.size() > 0) { if (dirList.indexOf(file1.getName()) != -1) { - // System.out.println(file1.getAbsolutePath()); + // System.out.println(file1.getAbsolutePath()); imageFolderPath = file1.getAbsolutePath() + "\\"; imgFun(imageFolderPath, file1, dirList, doc); @@ -248,7 +260,7 @@ public class PrintToPdfUtil { } } }else{ - // System.out.println("空文件夹"); + // System.out.println("空文件夹"); } @@ -260,7 +272,7 @@ public class PrintToPdfUtil { // 输入流 // FileOutputStream fos = new FileOutputStream(pdfPath); // // 创建文档 - Document doc = new Document(null, 0, 0, 0, 0); + Document doc = new Document(null, 0, 0, 0, 0); // //doc.open(); // // 写入PDF文档 @@ -289,52 +301,52 @@ public class PrintToPdfUtil { try { File[] files = file.listFiles(); if(file!=null) - if (files.length > 0) { - // 循环获取图片文件夹内的图片 - for (File file1 : files) { - if (file1.getName().endsWith(".pdf")) { - //System.out.println(file1.length()); - if (pdfList != null && pdfList.size() > 0) { - //System.out.println("文件名:"+file1.getName()); - if (pdfList.indexOf(file1.getName()) != -1) { - + if (files.length > 0) { + // 循环获取图片文件夹内的图片 + for (File file1 : files) { + if (file1.getName().endsWith(".pdf")) { + //System.out.println(file1.length()); + if (pdfList != null && pdfList.size() > 0) { + //System.out.println("文件名:"+file1.getName()); + if (pdfList.indexOf(file1.getName()) != -1) { + + }else{ + if (file1.length() == 0) { + //file.delete(); + } else { + pdfFolderPath = file1.getAbsolutePath(); + mergePdf.addSource(pdfFolderPath); + } + } }else{ if (file1.length() == 0) { //file.delete(); + } else { pdfFolderPath = file1.getAbsolutePath(); mergePdf.addSource(pdfFolderPath); } } - }else{ - if (file1.length() == 0) { - //file.delete(); - } else { - pdfFolderPath = file1.getAbsolutePath(); - mergePdf.addSource(pdfFolderPath); - } } - } + if (file1.isDirectory()) { + if (dirList != null && dirList.size() > 0) { + if (dirList.indexOf(file1.getName()) != -1) { + pdfFolderPath = file1.getAbsolutePath() + "\\"; + pdfFun(pdfFolderPath, file1, dirList, pdfList, mergePdf); - if (file1.isDirectory()) { - if (dirList != null && dirList.size() > 0) { - if (dirList.indexOf(file1.getName()) != -1) { - pdfFolderPath = file1.getAbsolutePath() + "\\"; + } + } else { + pdfFolderPath = file1.getAbsolutePath() + "\\"; pdfFun(pdfFolderPath, file1, dirList, pdfList, mergePdf); - } - } else { - pdfFolderPath = file1.getAbsolutePath() + "\\"; - pdfFun(pdfFolderPath, file1, dirList, pdfList, mergePdf); } - } + } + } else { + System.out.println("空文件夹"); } - } else { - System.out.println("空文件夹"); - } } catch (Exception e) { e.printStackTrace(); } @@ -389,7 +401,7 @@ public class PrintToPdfUtil { * 產生成功返回true, 否則返回false */ - public static boolean mergePdfFiles2(List files, String newfile) throws Exception { + public static boolean mergePdfFiles2(List files, String newfile) throws Exception { boolean retValue = false; List tmpFiles = new ArrayList<>(); @@ -507,7 +519,7 @@ public class PrintToPdfUtil { /** - * 复制单个文件 + * 复制单个文件并删除原有的pdf文件 * * @param oldPath String 原文件路径 如:c:/fqf.txt * @param newPath String 复制后路径 如:f:/fqf.txt @@ -541,61 +553,37 @@ public class PrintToPdfUtil { file2.delete(); } } - } - public static void main(String[] args) throws IOException { - String pdfFile = String.valueOf(System.currentTimeMillis()); - //读取指定路径下的文件名和目录名 - List list = new ArrayList(); - list.add("45646546"); - - //图片转PDF(病案号文件夹+类别文件夹) - // String str=toPdf("C:\\Users\\Administrator\\Desktop\\测试\\uploadImage\\", "C:\\Users\\Administrator\\Desktop\\测试\\" + "123.pdf", list); - // System.out.println(str); - //多个pdf合成一个 - //pdtToPdf("D:\\project_js\\EMR_Medical_Record\\src\\main\\webapp\\static\\img\\pdfFiles\\1333ad3c4d6448c89372835dbad3c364\\", "D:\\project_js\\EMR_Medical_Record\\src\\main\\webapp\\static\\img\\pdfFiles\\typesPdf\\"+ pdfFile+".pdf", list); - - //图片移动 - //moveTotherFolders("D:\\project_js\\EMR_Medical_Record\\src\\main\\webapp\\static\\img\\uploads\\1333ad3c4d6448c89372835dbad3c364\\HC3SL2HENH348M8X619PMCA7GC5R3125\\2019071905226021565006922724小程序界面.png","D:\\project_js\\EMR_Medical_Record\\src\\main\\webapp\\static\\img\\uploads\\1333ad3c4d6448c89372835dbad3c364\\SDV1QEHUPQRQ8GXJE4RQH0FGAS1V7HM0\\"); - //moveTotherFolders("D:\\project_js\\EMR_Medical_Record\\src\\main\\webapp/static\\img\\uploads\\1333ad3c4d6448c89372835dbad3c364\\HC3SL2HENH348M8X619PMCA7GC5R3125\\2019071905226021565064554400fw.jpg", "D:\\project_js\\EMR_Medical_Record\\src\\main\\webapp\\static\\img\\uploads\\1333ad3c4d6448c89372835dbad3c364\\3\\"); - List list1 = new ArrayList(); - list.add("C:\\Users\\HIPAA\\Desktop\\测试\\ttt.pdf"); - list.add("C:\\Users\\HIPAA\\Desktop\\测试\\sss.pdf"); - //String[] files = {"C:\\Users\\Administrator\\Desktop\\新建文件夹\\ttt.pdf", "C:\\Users\\Administrator\\Desktop\\新建文件夹\\sss.pdf"}; - String savepath = "C:\\Users\\HIPAA\\Desktop\\测试\\temp.pdf"; - //mergePdfFiles(list1, savepath); - //mergePdfFiles(list1, savepath); - //PrintToPdfUtil.copyFile("C:\\Users\\Administrator\\Desktop\\新建文件夹\\ttt.pdf", "C:\\Users\\Administrator\\Desktop\\新建文件夹\\123\\ttt.pdf"); - - List pdfList = new ArrayList(); - //pdfList.add("C:\\Users\\Administrator\\Desktop\\测试\\ttt.pdf"); - pdfList.add("C:\\Users\\HIPAA\\Desktop\\测试\\sss7.pdf"); - pdfList.add("C:\\Users\\HIPAA\\Desktop\\测试\\15511.pdf"); - //mergePdfFiles(pdfList, "C:\\Users\\Administrator\\Desktop\\测试\\合成.pdf"); - - ArrayList pdffiles = new ArrayList(); - //pdffiles.add("C:\\Users\\Administrator\\Desktop\\测试\\15511.pdf"); - // pdffiles.add("D:\\project\\yingde\\EMR_Medical_Record\\src\\main\\webapp\\static\\img\\pdfFiles\\0f6e6941028c44b8b8ea070f27480416\\HC3SL2HENH348M8X619PMCA7GC5R3125\\HC3SL2HENH348M8X619PMCA7GC5R3125.pdf"); - //boolean checkPdf=CheckPdfFiles(pdffiles); - - //System.out.println(checkPdf); - - //判断文件是否损坏 - //boolean bol=checkPdfFile("D:\\project\\yingde\\EMR_Medical_Record\\src\\main\\webapp\\static\\img\\pdfFiles\\0f6e6941028c44b8b8ea070f27480416\\HC3SL2HENH348M8X619PMCA7GC5R3125\\HC3SL2HENH348M8X619PMCA7GC5R3125.pdf"); - //System.out.println(bol); - - List files = new ArrayList(); - pdffiles.add("C:\\Users\\Administrator\\Desktop\\测试\\15511.pdf"); - pdffiles.add("C:\\Users\\Administrator\\Desktop\\测试\\153333511.pdf"); - //files.add(new File("C:\\Users\\Administrator\\Desktop\\测试\\123.pdf")); - //files.add(new File("C:\\Users\\Administrator\\Desktop\\测试\\sss.pdf")); - //files.add(new File("C:\\Users\\Administrator\\Desktop\\测试\\ttt333.pdf")); - //File f = mulFile2One(files, "C:\\Users\\Administrator\\Desktop\\测试\\mul2one.pdf"); + /** + * 复制单个文件 + * + * @param oldPath String 原文件路径 如:c:/fqf.txt + * @param newPath String 复制后路径 如:f:/fqf.txt + * @return boolean + */ + public static void copyFile2(String oldPath, String newPath) { + try { +// int bytesum = 0; + int byteread = 0; + File oldfile = new File(oldPath); + if (oldfile.exists()) { //文件存在时 + InputStream inStream = new FileInputStream(oldPath); //读入原文件 + FileOutputStream fs = new FileOutputStream(newPath); + byte[] buffer = new byte[1444]; +// int length; + while ((byteread = inStream.read(buffer)) != -1) { +// bytesum += byteread; //字节数 文件大小 +// System.out.println(bytesum); + fs.write(buffer, 0, byteread); + } + inStream.close(); + } + } catch (Exception e) { + System.out.println("复制单个文件操作出错"); + e.printStackTrace(); - //复制pdf文件 - /*File file=new File("C:\\Users\\Administrator\\Desktop\\images\\报表工具v2.4操作手册文档.pdf"); - save(file, "cc.pdf", "C:\\Users\\Administrator\\Desktop\\images");*/ + } } @@ -606,7 +594,6 @@ public class PrintToPdfUtil { //文件不存在 File file2 = new File(file); if (file2.exists()) { - //文件损坏 PdfReader reader = new PdfReader(file); Document document = new Document(reader.getPageSize(1)); @@ -618,7 +605,7 @@ public class PrintToPdfUtil { document.close(); //System.out.println("pdf 存在"); } else { - //System.out.println("pdf 不存在"); + //System.out.println("pdf 不存在"); } } catch (IOException e) { @@ -663,9 +650,300 @@ public class PrintToPdfUtil { } + /** + * 将PDF转化为图片 + * (使用 pdfbox) + * @param pdfPath PDF对象 + * @param page_end 要转换的页码,发票一般是一页,取第一页 + * @param imgPath 图片保存路径 + * @return + */ + public static List pdfToImage2(String pdfPath,int page_start,int page_end,String imgPath) { + String result=""; + List list=new ArrayList(); + Map map=null; + File file = new File(pdfPath); + if(file.exists()) { + SimpleDateFormat format2 = new SimpleDateFormat("yyyyMMddHHmmss"); + String nowTime = format2.format(new Date()); + String filePath =file.getName().substring(0,file.getName().lastIndexOf(".")); + + try { + PDDocument doc = PDDocument.load(file); + PDFRenderer renderer = new PDFRenderer(doc); + int pageCount = doc.getNumberOfPages(); + + File file2 =new File(imgPath); //此目录保存缩小后的关键图 + if(!file2.exists()){ + //如果要创建的多级目录不存在才需要创建。 + file2.mkdirs(); + } + String fileName=""; + for (int i = pageCount; i>0; i--) { + if ((i <=page_end && i>=(page_start))||(page_end==0 &&i==page_start)) { + map=new HashMap<>(); + BufferedImage image = renderer.renderImageWithDPI(i-1, 296); + // BufferedImage image = renderer.renderImage(i, 2.5f); + fileName=file.getName().substring(0,file.getName().lastIndexOf("."))+"_"+nowTime+"_" + (i)+ "." + DEFAULT_FORMAT; + ImageIO.write(image, DEFAULT_FORMAT, new File(imgPath + fileName)); + map.put("max_picture",imgPath + fileName); + map.put("picture_number",i+""); + list.add(map); + if(i == 1) { + doc.removePage(0); + }else{ + doc.removePage(i-1); + } + } + } + doc.save(pdfPath); + + } catch (IOException e) { + e.printStackTrace(); + } + }else{ + result="文件不存在!"; + } + + return list; + } + + /** + * 将PDF转化为图片 + * (使用 pdfbox) + * @param pdfPath PDF对象 + * @param page_end 要转换的页码,发票一般是一页,取第一页 + * @param imgPath 图片保存路径 + * @return + */ + public static List pdfToImage(String pdfPath,int page_start,int page_end,String imgPath) { + String result=""; + List list=new ArrayList(); + Map map=null; + File file = new File(pdfPath); + if(file.exists()) { + SimpleDateFormat format2 = new SimpleDateFormat("yyyyMMddHHmmss"); + String nowTime = format2.format(new Date()); + String filePath =file.getName().substring(0,file.getName().lastIndexOf(".")); + + try { + PDDocument doc = PDDocument.load(file); + PDFRenderer renderer = new PDFRenderer(doc); + int pageCount = doc.getNumberOfPages(); + + + String fileName=""; + String oleFileName=file.getName().substring(0,file.getName().lastIndexOf(".")); + for (int i = pageCount; i>0; i--) { + if ((i <=page_end && i>=(page_start))||(page_end==0 &&i==page_start)) { + map=new HashMap<>(); + BufferedImage image = renderer.renderImageWithDPI(i-1, 296); + // BufferedImage image = renderer.renderImage(i, 2.5f); + File file2 =new File(imgPath+oleFileName+"\\"); //此目录保存缩小后的关键图 + if(!file2.exists()){ + //如果要创建的多级目录不存在才需要创建。 + file2.mkdirs(); + } + fileName=oleFileName+"_"+nowTime+"_" + (i)+ "." + DEFAULT_FORMAT; + ImageIO.write(image, DEFAULT_FORMAT, new File(imgPath+oleFileName+"\\" + fileName)); + map.put("max_picture",imgPath+oleFileName+"\\" + fileName); + map.put("picture_number",i+""); + list.add(map); + if(i == 1) { + doc.removePage(0); + }else { + doc.removePage(i-1); + } + } + } + doc.save(pdfPath); + + } catch (IOException e) { + e.printStackTrace(); + } + }else{ + result="文件不存在!"; + } + + return list; + } + + public static void delete(File file) { + if(!file.exists()) return; + if(file.isFile() || file.list()==null) { + file.delete(); + // System.out.println("删除了"+file.getName()); + }else { + File[] files = file.listFiles(); + for(File a:files) { + delete(a); + } + file.delete(); + // System.out.println("删除了"+file.getName()); + } + + } + + + /** + * @description + * 针对页码生成的PDF事件监听 + * @author TianwYam + * @date 2019年12月28日下午8:51:08 + */ + public static class PageNumPdfPageEvent extends com.itextpdf.text.pdf.PdfPageEventHelper { + + @Override + public void onEndPage(com.itextpdf.text.pdf.PdfWriter writer, com.itextpdf.text.Document document) { + + try { + // PDF文档内容 + com.itextpdf.text.pdf.PdfContentByte pdfContent = writer.getDirectContent(); + pdfContent.saveState(); + pdfContent.beginText(); + int footerFontSize = 14 ; + + // 解决页码中文无法显示 或者 显示为乱码的问题 + // 但是必须引入jar包 itext-asian-5.2.0.jar + com.itextpdf.text.pdf.BaseFont baseFont = com.itextpdf.text.pdf.BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", false); + com.itextpdf.text.Font fontDetail = new com.itextpdf.text.Font(baseFont, footerFontSize, com.itextpdf.text.Font.NORMAL); + + pdfContent.setFontAndSize(baseFont, footerFontSize); + + // 页脚的页码 展示 + String footerNum = String.format("第%d页", writer.getPageNumber()); + Phrase phrase = new Phrase(footerNum, fontDetail); + + // 页码的 横轴 坐标 居中 + float x = ( document.left() + document.right() ) / 2 ; + // 页码的 纵轴 坐标 + float y = document.bottom(-10) ; + // 添加文本内容,进行展示页码 + com.itextpdf.text.pdf.ColumnText.showTextAligned(pdfContent, Element.ALIGN_CENTER, phrase, x, y, 0); + + pdfContent.endText(); + pdfContent.restoreState(); + } catch (Exception e) { + e.printStackTrace(); + } + + } + } + + /** + * @description + * 给PDF文件添加页码 + * @author TianwYam + * @date 2019年12月28日下午8:48:55 + * @param orgPdfPath 源PDF文件路径 + * @param outputPdfPath 加了页码的PDF文件路径 + * @return 返回添加了页码的PDF文件路径 + */ + public static String addPageNum (String orgPdfPath, String outputPdfPath) { + try ( + // 输出文件 流 + FileOutputStream fos = new FileOutputStream(outputPdfPath);){ + + // 新建文档,默认A4大小 + com.itextpdf.text.Document document = new com.itextpdf.text.Document(com.itextpdf.text.PageSize.A4); + com.itextpdf.text.pdf.PdfWriter writer = com.itextpdf.text.pdf.PdfWriter.getInstance(document, fos); + // 设置页面监听事件,必须在open方法前 + writer.setPageEvent(new PageNumPdfPageEvent()); + document.open(); + + // PDF内容体 + com.itextpdf.text.pdf.PdfContentByte pdfContent = writer.getDirectContent(); + // 读取 源PDF文件,进行一页一页复制,才能触发 添加页码的 页面监听事件 + com.itextpdf.text.pdf.PdfReader reader = new com.itextpdf.text.pdf.PdfReader(orgPdfPath); + // 获取 源文件总页数 + int num = reader.getNumberOfPages(); + // System.out.println("总页数:" + num); + // 页面数是从1开始的 + for (int i = 1; i <= num; i++) { + document.newPage(); + // 设置空页码进行展示 + writer.setPageEmpty(false); + com.itextpdf.text.pdf.PdfImportedPage page = writer.getImportedPage(reader, i); + // 复制好的页面,添加到内容去,触发事件监听 + pdfContent.addTemplate(page, 0, 0); + } + + document.close(); + reader.close(); + } catch (Exception e) { + e.printStackTrace(); + } + + return outputPdfPath ; + } + + + + + public static void main(String[] args) throws IOException { + String pdfFile = String.valueOf(System.currentTimeMillis()); + //读取指定路径下的文件名和目录名 + List list = new ArrayList(); + list.add("45646546"); + + //图片转PDF(病案号文件夹+类别文件夹) + // String str=toPdf("C:\\Users\\Administrator\\Desktop\\测试\\uploadImage\\", "C:\\Users\\Administrator\\Desktop\\测试\\" + "123.pdf", list); + // System.out.println(str); + //多个pdf合成一个 + //pdtToPdf("D:\\project_js\\EMR_Medical_Record\\src\\main\\webapp\\static\\img\\pdfFiles\\1333ad3c4d6448c89372835dbad3c364\\", "D:\\project_js\\EMR_Medical_Record\\src\\main\\webapp\\static\\img\\pdfFiles\\typesPdf\\"+ pdfFile+".pdf", list); + + //图片移动 + //moveTotherFolders("D:\\project_js\\EMR_Medical_Record\\src\\main\\webapp\\static\\img\\uploads\\1333ad3c4d6448c89372835dbad3c364\\HC3SL2HENH348M8X619PMCA7GC5R3125\\2019071905226021565006922724小程序界面.png","D:\\project_js\\EMR_Medical_Record\\src\\main\\webapp\\static\\img\\uploads\\1333ad3c4d6448c89372835dbad3c364\\SDV1QEHUPQRQ8GXJE4RQH0FGAS1V7HM0\\"); + //moveTotherFolders("D:\\project_js\\EMR_Medical_Record\\src\\main\\webapp/static\\img\\uploads\\1333ad3c4d6448c89372835dbad3c364\\HC3SL2HENH348M8X619PMCA7GC5R3125\\2019071905226021565064554400fw.jpg", "D:\\project_js\\EMR_Medical_Record\\src\\main\\webapp\\static\\img\\uploads\\1333ad3c4d6448c89372835dbad3c364\\3\\"); + List list1 = new ArrayList(); + list.add("C:\\Users\\HIPAA\\Desktop\\测试\\ttt.pdf"); + list.add("C:\\Users\\HIPAA\\Desktop\\测试\\sss.pdf"); + //String[] files = {"C:\\Users\\Administrator\\Desktop\\新建文件夹\\ttt.pdf", "C:\\Users\\Administrator\\Desktop\\新建文件夹\\sss.pdf"}; + String savepath = "C:\\Users\\HIPAA\\Desktop\\测试\\temp.pdf"; + //mergePdfFiles(list1, savepath); + //mergePdfFiles(list1, savepath); + // PrintToPdfUtil.copyFile2("C:\\Users\\Administrator\\Desktop\\test\\delPicImg\\新建文件夹\\ttt.pdf", "C:\\Users\\Administrator\\Desktop\\test\\delPicImg\\新建文件夹\\3.pdf"); + + List pdfList = new ArrayList(); + //pdfList.add("C:\\Users\\Administrator\\Desktop\\测试\\ttt.pdf"); + pdfList.add("C:\\Users\\HIPAA\\Desktop\\测试\\sss7.pdf"); + pdfList.add("C:\\Users\\HIPAA\\Desktop\\测试\\15511.pdf"); + //mergePdfFiles(pdfList, "C:\\Users\\Administrator\\Desktop\\测试\\合成.pdf"); + + ArrayList pdffiles = new ArrayList(); + //pdffiles.add("C:\\Users\\Administrator\\Desktop\\测试\\15511.pdf"); + // pdffiles.add("D:\\project\\yingde\\EMR_Medical_Record\\src\\main\\webapp\\static\\img\\pdfFiles\\0f6e6941028c44b8b8ea070f27480416\\HC3SL2HENH348M8X619PMCA7GC5R3125\\HC3SL2HENH348M8X619PMCA7GC5R3125.pdf"); + //boolean checkPdf=CheckPdfFiles(pdffiles); + + //System.out.println(checkPdf); + + //判断文件是否损坏 + //boolean bol=checkPdfFile("D:\\project\\yingde\\EMR_Medical_Record\\src\\main\\webapp\\static\\img\\pdfFiles\\0f6e6941028c44b8b8ea070f27480416\\HC3SL2HENH348M8X619PMCA7GC5R3125\\HC3SL2HENH348M8X619PMCA7GC5R3125.pdf"); + //System.out.println(bol); + + List files = new ArrayList(); + pdffiles.add("C:\\Users\\Administrator\\Desktop\\测试\\15511.pdf"); + pdffiles.add("C:\\Users\\Administrator\\Desktop\\测试\\153333511.pdf"); + //files.add(new File("C:\\Users\\Administrator\\Desktop\\测试\\123.pdf")); + //files.add(new File("C:\\Users\\Administrator\\Desktop\\测试\\sss.pdf")); + //files.add(new File("C:\\Users\\Administrator\\Desktop\\测试\\ttt333.pdf")); + //File f = mulFile2One(files, "C:\\Users\\Administrator\\Desktop\\测试\\mul2one.pdf"); + + //复制pdf文件 + /*File file=new File("C:\\Users\\Administrator\\Desktop\\images\\报表工具v2.4操作手册文档.pdf"); + save(file, "cc.pdf", "C:\\Users\\Administrator\\Desktop\\images");*/ + String fileName="C:\\Users\\HIPAA\\Desktop\\测试\\sss7.pdf"; + fileName = fileName.substring(fileName.lastIndexOf("\\")+1).replace(".pdf",""); + + System.out.println("方法二:fileName = " + fileName); + + + } + + } - + diff --git a/src/main/java/com/emr/util/pdfDelPageTest.java b/src/main/java/com/emr/util/pdfDelPageTest.java index c60f063c..110073d5 100644 --- a/src/main/java/com/emr/util/pdfDelPageTest.java +++ b/src/main/java/com/emr/util/pdfDelPageTest.java @@ -119,4 +119,6 @@ public class pdfDelPageTest { System.out.println("已经转完了哦"); return 1; } + + } diff --git a/src/main/resources/mapper/Archive_DetailMapper.xml b/src/main/resources/mapper/Archive_DetailMapper.xml index cc360aa7..e1efe7a7 100644 --- a/src/main/resources/mapper/Archive_DetailMapper.xml +++ b/src/main/resources/mapper/Archive_DetailMapper.xml @@ -13,7 +13,7 @@ - + @@ -34,7 +34,7 @@ - + @@ -43,7 +43,7 @@ id, PDF_PATH, MasterID, UpLoadDateTime, AssortID, Source, SubAssort, Title, flag, - Sys,page_number + Sys,page_number,recover_pdf_path + select + + from archive_detail_picture + where id = #{id,jdbcType=INTEGER} + ORDER BY picture_number + + + + delete from archive_detail_picture + where 1=1 + + and id=#{id,jdbcType=INTEGER} + + + and parent_id=#{parentId,jdbcType=VARCHAR} + + + and max_picture like #{maxPicture,jdbcType=VARCHAR}+'%' + + + + insert into archive_detail_picture (id, parent_id, min_picture, + max_picture, picture_number, effective, + creater, create_time, updater, + update_time, remark) + values (#{id,jdbcType=INTEGER}, #{parentId,jdbcType=VARCHAR}, #{minPicture,jdbcType=VARCHAR}, + #{maxPicture,jdbcType=VARCHAR}, #{pictureNumber,jdbcType=INTEGER}, #{effective,jdbcType=INTEGER}, + #{creater,jdbcType=VARCHAR}, #{createTime,jdbcType=VARCHAR}, #{updater,jdbcType=VARCHAR}, + #{updateTime,jdbcType=VARCHAR}, #{remark,jdbcType=VARCHAR}) + + + insert into archive_detail_picture + + + id, + + + parent_id, + + + min_picture, + + + max_picture, + + + picture_number, + + + effective, + + + creater, + + + create_time, + + + updater, + + + update_time, + + + remark, + + + + + #{id,jdbcType=INTEGER}, + + + #{parentId,jdbcType=VARCHAR}, + + + #{minPicture,jdbcType=VARCHAR}, + + + #{maxPicture,jdbcType=VARCHAR}, + + + #{pictureNumber,jdbcType=INTEGER}, + + + #{effective,jdbcType=INTEGER}, + + + #{creater,jdbcType=VARCHAR}, + + + #{createTime,jdbcType=VARCHAR}, + + + #{updater,jdbcType=VARCHAR}, + + + #{updateTime,jdbcType=VARCHAR}, + + + #{remark,jdbcType=VARCHAR}, + + + + + update archive_detail_picture + + + parent_id = #{parentId,jdbcType=VARCHAR}, + + + min_picture = #{minPicture,jdbcType=VARCHAR}, + + + max_picture = #{maxPicture,jdbcType=VARCHAR}, + + + picture_number = #{pictureNumber,jdbcType=INTEGER}, + + + effective = #{effective,jdbcType=INTEGER}, + + + creater = #{creater,jdbcType=VARCHAR}, + + + create_time = #{createTime,jdbcType=VARCHAR}, + + + updater = #{updater,jdbcType=VARCHAR}, + + + update_time = #{updateTime,jdbcType=VARCHAR}, + + + remark = #{remark,jdbcType=VARCHAR}, + + + where id = #{id,jdbcType=INTEGER} + + + update archive_detail_picture + set parent_id = #{parentId,jdbcType=VARCHAR}, + min_picture = #{minPicture,jdbcType=VARCHAR}, + max_picture = #{maxPicture,jdbcType=VARCHAR}, + picture_number = #{pictureNumber,jdbcType=INTEGER}, + effective = #{effective,jdbcType=INTEGER}, + creater = #{creater,jdbcType=VARCHAR}, + create_time = #{createTime,jdbcType=VARCHAR}, + updater = #{updater,jdbcType=VARCHAR}, + update_time = #{updateTime,jdbcType=VARCHAR}, + remark = #{remark,jdbcType=VARCHAR} + where id = #{id,jdbcType=INTEGER} + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/views/beHospitaledDir/beHospList.jsp b/src/main/webapp/WEB-INF/views/beHospitaledDir/beHospList.jsp index 5064d829..5aaf0437 100644 --- a/src/main/webapp/WEB-INF/views/beHospitaledDir/beHospList.jsp +++ b/src/main/webapp/WEB-INF/views/beHospitaledDir/beHospList.jsp @@ -1,4 +1,4 @@ -<%@ page contentType="text/html;charset=UTF-8" language="java" import="java.util.*" %> +<%@ page contentType="text/html;charset=UTF-8" language="java" import="java.util.*" %> <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <% @@ -19,6 +19,7 @@ <%----%> - +
@@ -685,22 +756,22 @@ <%--发大弹窗--%> - - <%--删除pdf某页弹窗--%>