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

@ -531,9 +531,9 @@ public class Sprt01Controller extends ApplicationController {
* @return PDF
*/
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);
return mav;
@ -544,9 +544,9 @@ public class Sprt01Controller extends ApplicationController {
* @return
*/
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);
return mav;
@ -569,9 +569,9 @@ public class Sprt01Controller extends ApplicationController {
* @return PDF
*/
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);
return mav;
@ -581,9 +581,9 @@ public class Sprt01Controller extends ApplicationController {
* @return
*/
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);
return mav;

@ -134,25 +134,34 @@ $(document).ready(function(){
crdnIds : $P.crdnIds.join(","),
taskSeCd : taskSeCd
};
var inBrowser = false;
if(fileType == "pdf"){
submitParam.paperSeCd = paper;
inBrowser = true;
}
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}");
}
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;
}
}
}
});
}
$P.fnOpenOtptStng = () => {

@ -132,25 +132,33 @@ $(document).ready(function(){
crdnIds : $P.crdnIds.join(","),
taskSeCd : taskSeCd
};
var inBrowser = false;
if(fileType == "pdf"){
submitParam.paperSeCd = paper;
inBrowser = true;
}
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}");
}
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;
}
}
}
});
}
$P.fnOpenOtptStng = () => {

@ -759,14 +759,18 @@ $(document).ready(function(){
return;
}
ajax.post({
url : url,
data : submitParam,
success : (resp) => {
if(resp.filePath != null && resp.filePath != ""){
openPDF(resp.filePath, resp.fileName, "pdf_sample");
}
}
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, "pdf_sample");
});
}

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

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

Loading…
Cancel
Save