pdf파일 다운로드 및 출력 수정

main
이범준 9 months ago
parent 835873e7f3
commit 25dabf1448

@ -30,6 +30,8 @@ public class PDFPrintUtil extends PrintUtil {
private float[] paperMilimeter = new float[2]; private float[] paperMilimeter = new float[2];
private String formatKorName;
public void setting(String paperType) { public void setting(String paperType) {
if(paperType.equals("01")) { if(paperType.equals("01")) {
this.paperMilimeter = new float[] {210.0f , 297.0f}; this.paperMilimeter = new float[] {210.0f , 297.0f};
@ -38,6 +40,14 @@ public class PDFPrintUtil extends PrintUtil {
} }
} }
public String getFormatKorName() {
return this.formatKorName;
}
public String setFormatKorName(String formatKorName) {
return this.formatKorName = formatKorName;
}
public String filePathForNewFile() { public String filePathForNewFile() {
SimpleDateFormat ymdhmsFormat = new SimpleDateFormat("yyyyMMddHHmmss"); SimpleDateFormat ymdhmsFormat = new SimpleDateFormat("yyyyMMddHHmmss");
@ -514,5 +524,4 @@ public class PDFPrintUtil extends PrintUtil {
} }
} }
} }

@ -34,15 +34,31 @@ public interface IntegrationSearchService {
/** . /** .
* @param formatType ,formatName , printOption , crdnIds * @param formatType ,formatName , printOption , crdnIds
* @return map * @return map
* <ul><li>filePath: </li> * <ul><li>filename: </li>
* <li>fileName: </li> * <li>filePath: </li>
* <li>file: </li>
* </ul> * </ul>
*/ */
Map<String, Object> makeFileFromHwpFormat(String formatType, String formatName, PrintOption printOption, String... crdnIds); Map<String, Object> makeFileFromHwpFormat(String formatType, String formatName, PrintOption printOption, String... crdnIds);
// Map<String, String> makeFileFromHwpFormat(String formatType, String formatName, PrintOption printOption, String... crdnIds);
Map<String, String> makePdfFile(String formatType, String formatName, PrintOption printOption, String[] crdnIds); /** pdf .
* @param formatType ,formatName , printOption , crdnIds
* @return map
* <ul><li>filename: </li>
* <li>filePath: </li>
* <li>file: </li>
* </ul>
*/
Map<String, Object> makePdfFile(String formatType, String formatName, PrintOption printOption, String[] crdnIds);
Map<String, String> makeOutsourcingFile(String formatName, PrintOption printOption, String[] crdnIds); /** .
* @param formatName , printOption , crdnIds
* @return map
* <ul><li>filename: </li>
* <li>filePath: </li>
* <li>file: </li>
* </ul>
*/
Map<String, Object> makeOutsourcingFile(String formatName, PrintOption printOption, String[] crdnIds);
} }

@ -292,8 +292,8 @@ public class IntegrationSearchServiceBean extends AbstractServiceBean implements
} }
@Override @Override
public Map<String, String> makePdfFile(String formatType, String formatName, PrintOption printOption, String[] crdnIds) { public Map<String, Object> makePdfFile(String formatType, String formatName, PrintOption printOption, String[] crdnIds) {
Map<String, String> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
PDFPrintFormat pdfFormat = null; PDFPrintFormat pdfFormat = null;
if(formatName.equals("advntce")) { if(formatName.equals("advntce")) {
@ -317,6 +317,12 @@ public class IntegrationSearchServiceBean extends AbstractServiceBean implements
PDFPrintUtil pdfPrintUtil = new PDFPrintUtil(); PDFPrintUtil pdfPrintUtil = new PDFPrintUtil();
if(formatName.equals("advntce")) {
pdfPrintUtil.setFormatKorName("사전통지서");
} else if(formatName.equals("nht")) {
pdfPrintUtil.setFormatKorName("고지서");
}
UserInfo userInfo = currentUser(); UserInfo userInfo = currentUser();
factionBean.initUserInfo(userInfo); factionBean.initUserInfo(userInfo);
pdfPrintUtil.setPrintRequestUserInfo(userInfo); pdfPrintUtil.setPrintRequestUserInfo(userInfo);
@ -598,8 +604,10 @@ public class IntegrationSearchServiceBean extends AbstractServiceBean implements
doc.save(resultFilePath); doc.save(resultFilePath);
doc.close(); doc.close();
result.put("fileName", "사전통지서.pdf"); String downloadFileName = pdfPrintUtil.getFormatKorName()+"_"+pdfPrintUtil.getPrintRequestDt()+".pdf";
result.put("filename", downloadFileName);
result.put("filePath", resultFilePath); result.put("filePath", resultFilePath);
result.put("file", new File(resultFilePath));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
@ -610,8 +618,8 @@ public class IntegrationSearchServiceBean extends AbstractServiceBean implements
} }
@Override @Override
public Map<String, String> makeOutsourcingFile(String formatName, PrintOption printOption, String[] crdnIds) { public Map<String, Object> makeOutsourcingFile(String formatName, PrintOption printOption, String[] crdnIds) {
Map<String,String> result = new HashMap<>(); Map<String, Object> result = new HashMap<>();
Hangul hangul = new Hangul(2); Hangul hangul = new Hangul(2);
@ -728,8 +736,9 @@ public class IntegrationSearchServiceBean extends AbstractServiceBean implements
zipFile.addFolder(new File(imagesFolderPath)); zipFile.addFolder(new File(imagesFolderPath));
zipFile.close(); zipFile.close();
result.put("filename", zipFileName);
result.put("filePath", zipFilePath); result.put("filePath", zipFilePath);
result.put("fileName", zipFileName); result.put("file", new File(zipFilePath));
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException("외주파일생성 중 오류가 발생하였습니다."); throw new RuntimeException("외주파일생성 중 오류가 발생하였습니다.");

@ -531,9 +531,9 @@ public class Sprt01Controller extends ApplicationController {
* @return PDF * @return PDF
*/ */
public ModelAndView makeAdvntcePdf(PrintOption printOption, String[] crdnIds) { public ModelAndView makeAdvntcePdf(PrintOption printOption, String[] crdnIds) {
ModelAndView mav = new ModelAndView("jsonView"); ModelAndView mav = new ModelAndView("downloadView");
Map<String,String> result = integrationSearchService.makePdfFile("info", "advntce", printOption, crdnIds); Map<String, Object> result = integrationSearchService.makePdfFile("info", "advntce", printOption, crdnIds);
mav.addAllObjects(result); mav.addAllObjects(result);
return mav; return mav;
@ -544,9 +544,9 @@ public class Sprt01Controller extends ApplicationController {
* @return * @return
*/ */
public ModelAndView makeAdvntceOutsourcing(PrintOption printOption, String[] crdnIds) { public ModelAndView makeAdvntceOutsourcing(PrintOption printOption, String[] crdnIds) {
ModelAndView mav = new ModelAndView("jsonView"); ModelAndView mav = new ModelAndView("downloadView");
Map<String,String> result = integrationSearchService.makeOutsourcingFile("advntce", printOption, crdnIds); Map<String, Object> result = integrationSearchService.makeOutsourcingFile("advntce", printOption, crdnIds);
mav.addAllObjects(result); mav.addAllObjects(result);
return mav; return mav;
@ -569,9 +569,9 @@ public class Sprt01Controller extends ApplicationController {
* @return PDF * @return PDF
*/ */
public ModelAndView makeNhtPdf(PrintOption printOption, String[] crdnIds) { public ModelAndView makeNhtPdf(PrintOption printOption, String[] crdnIds) {
ModelAndView mav = new ModelAndView("jsonView"); ModelAndView mav = new ModelAndView("downloadView");
Map<String,String> result = integrationSearchService.makePdfFile("info", "nht", printOption, crdnIds); Map<String, Object> result = integrationSearchService.makePdfFile("info", "nht", printOption, crdnIds);
mav.addAllObjects(result); mav.addAllObjects(result);
return mav; return mav;
@ -581,9 +581,9 @@ public class Sprt01Controller extends ApplicationController {
* @return * @return
*/ */
public ModelAndView makeNhtOutsourcing(PrintOption printOption, String[] crdnIds) { public ModelAndView makeNhtOutsourcing(PrintOption printOption, String[] crdnIds) {
ModelAndView mav = new ModelAndView("jsonView"); ModelAndView mav = new ModelAndView("downloadView");
Map<String,String> result = integrationSearchService.makeOutsourcingFile("nht", printOption, crdnIds); Map<String, Object> result = integrationSearchService.makeOutsourcingFile("nht", printOption, crdnIds);
mav.addAllObjects(result); mav.addAllObjects(result);
return mav; return mav;

@ -134,25 +134,34 @@ $(document).ready(function(){
crdnIds : $P.crdnIds.join(","), crdnIds : $P.crdnIds.join(","),
taskSeCd : taskSeCd taskSeCd : taskSeCd
}; };
var inBrowser = false;
if(fileType == "pdf"){ if(fileType == "pdf"){
submitParam.paperSeCd = paper; submitParam.paperSeCd = paper;
inBrowser = true;
} }
ajax.post({
url : url, if(inBrowser){
data : submitParam,
success : (resp) => { var parameter = toQuery(submitParam);
if(resp.filePath != null && resp.filePath != ""){ var filenameInHeader = "";
if(fileType == "pdf"){ fetch(url + "?" + parameter)
openPDF(resp.filePath, resp.fileName, resp.fileName); .then((response) => {
} else { var header = response.headers.get('Content-Disposition');
downloadFile(resp.filePath, resp.fileName, "tempArea--${pageName}"); var parts = header.split(';');
} filenameInHeader = decodeURIComponent(parts[1].split('=')[1]);
return response.blob();
} })
} .then((blob) => {
}); openPDF(blob, filenameInHeader);
});
} else {
var parameter = toQuery(submitParam);
document.location.href = url + "?" + parameter;
}
} }
$P.fnOpenOtptStng = () => { $P.fnOpenOtptStng = () => {

@ -132,25 +132,33 @@ $(document).ready(function(){
crdnIds : $P.crdnIds.join(","), crdnIds : $P.crdnIds.join(","),
taskSeCd : taskSeCd taskSeCd : taskSeCd
}; };
var inBrowser = false;
if(fileType == "pdf"){ if(fileType == "pdf"){
submitParam.paperSeCd = paper; submitParam.paperSeCd = paper;
inBrowser = true;
}
if(inBrowser){
var parameter = toQuery(submitParam);
var filenameInHeader = "";
fetch(url + "?" + parameter)
.then((response) => {
var header = response.headers.get('Content-Disposition');
var parts = header.split(';');
filenameInHeader = decodeURIComponent(parts[1].split('=')[1]);
return response.blob();
})
.then((blob) => {
openPDF(blob, filenameInHeader);
});
} else {
var parameter = toQuery(submitParam);
document.location.href = url + "?" + parameter;
} }
ajax.post({
url : url,
data : submitParam,
success : (resp) => {
if(resp.filePath != null && resp.filePath != ""){
if(fileType == "pdf"){
openPDF(resp.filePath, resp.fileName, resp.fileName);
} else {
downloadFile(resp.filePath, resp.fileName, "tempArea--${pageName}");
}
}
}
});
} }
$P.fnOpenOtptStng = () => { $P.fnOpenOtptStng = () => {

@ -759,16 +759,20 @@ $(document).ready(function(){
return; return;
} }
ajax.post({ var parameter = toQuery(submitParam);
url : url, var filenameInHeader = "";
data : submitParam,
success : (resp) => { fetch(url + "?" + parameter)
if(resp.filePath != null && resp.filePath != ""){ .then((response) => {
openPDF(resp.filePath, resp.fileName, "pdf_sample"); var header = response.headers.get('Content-Disposition');
} var parts = header.split(';');
} filenameInHeader = decodeURIComponent(parts[1].split('=')[1]);
return response.blob();
})
.then((blob) => {
openPDF(blob, "pdf_sample");
}); });
} }
//배경이미지 출력 순서 고정 //배경이미지 출력 순서 고정

@ -51,17 +51,13 @@
<script src="/resources/js/base/base-fims.js"></script> <script src="/resources/js/base/base-fims.js"></script>
<script src="/resources/js/fims/framework/pdfobject.js"></script> <script src="/resources/js/fims/framework/pdfobject.js"></script>
<script language="javascript"> <script>
var pdfPath = location.search.split("=")[1];
pdfPath = pdfPath.replaceAll("%5c","/");
var curPage = location.href; function makePdfFromBlob(blob){
var center = location.pathname; var url = URL.createObjectURL(blob);
var end = location.search; PDFObject.embed(url, "#example");
}
var start = curPage.replace(center+end,"/");
PDFObject.embed(start+pdfPath, "#example");
</script> </script>
</body> </body>

@ -43,7 +43,7 @@ function focusOK() {
/************************************************************************** /**************************************************************************
* 파일 다운로드 * 파일 다운로드
**************************************************************************/ **************************************************************************/
function download(filePath, fileName, tempAreaId){ function downloadFile(filePath, fileName, tempAreaId){
var a = document.createElement("a"); var a = document.createElement("a");
a.href = resp.filePath; a.href = resp.filePath;
a.download = resp.fileName; a.download = resp.fileName;
@ -55,14 +55,16 @@ function download(filePath, fileName, tempAreaId){
/************************************************************************** /**************************************************************************
* pdf파일 미리보기 * pdf파일 미리보기
**************************************************************************/ **************************************************************************/
function openPDF(filePath, fileName, windowName){ function openPDF(blob, windowName){
filePath = filePath.replaceAll("\\","%5c");
var popup = window.open(
window.open( wctx.url("/resources/html/pdf.html")
wctx.url("/resources/html/pdf.html"+"?"+"path="+filePath)
,windowName ,windowName
,'top=10, left=10' ,'top=10, left=10'
); );
popup.onload = () => {
popup.makePdfFromBlob(blob);
};
} }
/************************************************************************** /**************************************************************************

Loading…
Cancel
Save