Merge branch 'tolag'
This commit is contained in:
commit
9d10971246
@ -1,12 +1,22 @@
|
||||
package itn.com.cmm.util;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.pdfbox.pdmodel.PDDocument;
|
||||
import org.apache.pdfbox.pdmodel.PDPage;
|
||||
import org.apache.pdfbox.pdmodel.PDPageContentStream;
|
||||
import org.apache.pdfbox.pdmodel.common.PDRectangle;
|
||||
import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author : 이호영
|
||||
@ -88,4 +98,53 @@ public final class PdfUtil {
|
||||
}
|
||||
|
||||
|
||||
public static String makeImgPdf(String imgDir,String extsn) throws Exception {
|
||||
PDDocument doc = new PDDocument();
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
try {
|
||||
File copy1 = new File(imgDir);
|
||||
File copy2 = new File(imgDir + "." +extsn);
|
||||
|
||||
|
||||
FileUtils.copyFile(copy1, copy2);
|
||||
File imgFiles = new File(imgDir + "." +extsn);
|
||||
Image img = ImageIO.read(imgFiles);
|
||||
|
||||
PDPage page = new PDPage(PDRectangle.A4);
|
||||
doc.addPage(page);
|
||||
|
||||
PDImageXObject pdImage = PDImageXObject.createFromFile(imgFiles.toString(), doc);
|
||||
int pageWidth = Math.round(page.getCropBox().getWidth());
|
||||
int pageHeight = Math.round(page.getCropBox().getHeight());
|
||||
|
||||
float imgRatio = 1;
|
||||
if ( pageWidth < img.getWidth(null)) {
|
||||
imgRatio = (float)img.getWidth(null) / (float)pageWidth;
|
||||
}
|
||||
|
||||
int imgWidth = Math.round(img.getWidth(null) / imgRatio);
|
||||
int imgHeight = Math.round(img.getHeight(null) / imgRatio);
|
||||
|
||||
int pageWidthPosition = (pageWidth - imgWidth) / 2;
|
||||
int pageHeightPosition = (pageWidth - imgWidth) / 2;
|
||||
|
||||
PDPageContentStream contents = new PDPageContentStream(doc, page);
|
||||
contents.drawImage(pdImage, pageWidthPosition, pageHeightPosition, imgWidth, imgHeight);
|
||||
contents.close();
|
||||
doc.save("/usr/local/tomcat/file/sht/pdf/" + uuid + ".pdf");
|
||||
|
||||
} catch (Exception e) {
|
||||
System.out.println("Exception! : " + e.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
doc.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return "/usr/local/tomcat/file/sht/pdf/" + uuid + ".pdf";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package itn.let.mjo.msg.web;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URL;
|
||||
import java.text.SimpleDateFormat;
|
||||
@ -13,7 +14,6 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.stream.Collector;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@ -52,6 +52,7 @@ import itn.com.cmm.service.EgovFileMngService;
|
||||
import itn.com.cmm.service.EgovFileMngUtil;
|
||||
import itn.com.cmm.service.FileVO;
|
||||
import itn.com.cmm.util.MJUtil;
|
||||
import itn.com.cmm.util.PdfUtil;
|
||||
import itn.com.cmm.util.RedirectUrlMaker;
|
||||
import itn.com.cmm.util.StringUtil;
|
||||
import itn.com.utl.fcc.service.EgovStringUtil;
|
||||
@ -158,6 +159,9 @@ public class MjonMsgController {
|
||||
@Resource(name = "egovMberCmpHstService")
|
||||
private EgovMberCmpHstService egovMberCmpHstService;
|
||||
|
||||
@Resource(name = "EgovFileMngService")
|
||||
private EgovFileMngService fileService;
|
||||
|
||||
//배열 정의{"컬럼순차번호, 컬럼이름, 컬럼내용, 컬럼이름에 붙여야할 내용(엑셀코드양식다운로드시 필요)"}
|
||||
private String[][] sendMsgExcelValue ={
|
||||
{"0" ,"번호" , "1" , "" },
|
||||
@ -5039,6 +5043,26 @@ public class MjonMsgController {
|
||||
return "/uss/ion/msg/weekendCsWork2";
|
||||
}
|
||||
|
||||
@RequestMapping(value = {"/uss/ion/msg/pdfView.do"})
|
||||
public String pdfView(FileVO fileVO, ModelMap model) throws Exception {
|
||||
|
||||
FileVO fvo = fileService.selectFileInf(fileVO);
|
||||
String path = "";
|
||||
|
||||
if(fvo != null) {
|
||||
if("pdf".equals(fvo.getFileExtsn())) {
|
||||
path = "/cmm/fms/FileDown.do?atchFileId="+ fvo.getAtchFileId() + "&fileSn=" + fvo.getFileSn();
|
||||
}else {
|
||||
String storePath = fvo.getFileStreCours() + fvo.getStreFileNm();
|
||||
path = PdfUtil.makeImgPdf(storePath, fvo.getFileExtsn());
|
||||
}
|
||||
}
|
||||
|
||||
model.addAttribute("pdfPath", path);
|
||||
|
||||
return "/uss/ion/msg/pdfView";
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -151,6 +151,7 @@
|
||||
|
||||
<pattern>/uss/ion/msg/weekendCsWork.do</pattern>
|
||||
<pattern>/uss/ion/msg/weekendCsWork2.do</pattern>
|
||||
<pattern>/uss/ion/msg/pdfView.do</pattern>
|
||||
|
||||
</decorator>
|
||||
|
||||
|
||||
134
src/main/webapp/WEB-INF/jsp/uss/ion/msg/pdfView.jsp
Normal file
134
src/main/webapp/WEB-INF/jsp/uss/ion/msg/pdfView.jsp
Normal file
@ -0,0 +1,134 @@
|
||||
<%--
|
||||
Class Name : weekendCsWork.jsp
|
||||
Description : 발신번호 리스트 조회 페이지
|
||||
Modification Information
|
||||
|
||||
수정일 수정자 수정내용
|
||||
------- -------- ---------------------------
|
||||
2021.03.31 신명섭 최초 생성
|
||||
|
||||
Copyright (C) 2009 by ITN All right reserved.
|
||||
--%>
|
||||
<%@ page contentType="text/html; charset=utf-8"%>
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
||||
<%@ taglib prefix="ui" uri="http://egovframework.gov/ctl/ui"%>
|
||||
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
|
||||
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
|
||||
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
|
||||
<%@ taglib prefix="ec" uri="/WEB-INF/tld/ecnet_tld.tld"%>
|
||||
<%
|
||||
response.setHeader("Cache-Control","no-store");
|
||||
response.setHeader("Pragma","no-cache");
|
||||
response.setDateHeader("Expires",0);
|
||||
if (request.getProtocol().equals("HTTP/1.1")) response.setHeader("Cache-Control", "no-cache");
|
||||
%>
|
||||
<!DOCTYPE html>
|
||||
<html lang="ko">
|
||||
|
||||
<head>
|
||||
<script type="text/javascript" src="<c:url value='/js/EgovMultiFile.js'/>"></script>
|
||||
<script src="//mozilla.github.io/pdf.js/build/pdf.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div>
|
||||
<button id="prev">Previous</button>
|
||||
<button id="next">Next</button>
|
||||
|
||||
<span>Page: <span id="page_num"></span> / <span id="page_count"></span></span>
|
||||
</div>
|
||||
<canvas id="the-canvas" name="the-canvas"></canvas>
|
||||
</body>
|
||||
</html>
|
||||
<script type="text/javaScript" language="javascript">
|
||||
var pdfDoc = null;
|
||||
var pageNum = 1;
|
||||
var pageRendering = false;
|
||||
var pageNumPending = null;
|
||||
var scale = 0.8;
|
||||
var canvas = document.getElementById('the-canvas');
|
||||
var ctx = canvas.getContext('2d');
|
||||
/* var url = '/cmm/fms/FileDown.do?atchFileId=FILE_000000000019061&fileSn=0'; */
|
||||
// var url = '/usr/local/tomcat/file/sht/pdf/2ccbb16e-62df-48c0-bbb1-3b6559bd4c36.pdf';
|
||||
var url = '<c:url value="${pdfPath}"/>';
|
||||
|
||||
/**
|
||||
* Get page info from document, resize canvas accordingly, and render page.
|
||||
* @param num Page number.
|
||||
*/
|
||||
function renderPage(num) {
|
||||
pageRendering = true;
|
||||
// Using promise to fetch the page
|
||||
pdfDoc.getPage(num).then(function(page) {
|
||||
var viewport = page.getViewport({scale: scale});
|
||||
canvas.height = viewport.height;
|
||||
canvas.width = viewport.width;
|
||||
|
||||
// Render PDF page into canvas context
|
||||
var renderContext = {
|
||||
canvasContext: ctx,
|
||||
viewport: viewport
|
||||
};
|
||||
var renderTask = page.render(renderContext);
|
||||
|
||||
// Wait for rendering to finish
|
||||
renderTask.promise.then(function() {
|
||||
pageRendering = false;
|
||||
if (pageNumPending !== null) {
|
||||
// New page rendering is pending
|
||||
renderPage(pageNumPending);
|
||||
pageNumPending = null;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Update page counters
|
||||
document.getElementById('page_num').textContent = num;
|
||||
}
|
||||
|
||||
/**
|
||||
* If another page rendering in progress, waits until the rendering is
|
||||
* finised. Otherwise, executes rendering immediately.
|
||||
*/
|
||||
function queueRenderPage(num) {
|
||||
if (pageRendering) {
|
||||
pageNumPending = num;
|
||||
} else {
|
||||
renderPage(num);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays previous page.
|
||||
*/
|
||||
function onPrevPage() {
|
||||
if (pageNum <= 1) {
|
||||
return;
|
||||
}
|
||||
pageNum--;
|
||||
queueRenderPage(pageNum);
|
||||
}
|
||||
document.getElementById('prev').addEventListener('click', onPrevPage);
|
||||
|
||||
/**
|
||||
* Displays next page.
|
||||
*/
|
||||
function onNextPage() {
|
||||
if (pageNum >= pdfDoc.numPages) {
|
||||
return;
|
||||
}
|
||||
pageNum++;
|
||||
queueRenderPage(pageNum);
|
||||
}
|
||||
document.getElementById('next').addEventListener('click', onNextPage);
|
||||
/**
|
||||
* Asynchronously downloads PDF.
|
||||
*/
|
||||
pdfjsLib.getDocument(url).promise.then(function(pdfDoc_) {
|
||||
pdfDoc = pdfDoc_;
|
||||
document.getElementById('page_count').textContent = pdfDoc.numPages;
|
||||
|
||||
// Initial/first page rendering
|
||||
renderPage(pageNum);
|
||||
});
|
||||
</script>
|
||||
Loading…
Reference in New Issue
Block a user