pdf출력 수정

main
이범준 7 months ago
parent 8b13423392
commit 300b6e2efd

@ -1,7 +1,10 @@
package cokr.xit.fims.cmmn.pdf.print;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
@ -13,6 +16,8 @@ import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject;
import org.apache.pdfbox.pdmodel.graphics.state.RenderingMode;
import org.springframework.core.io.ClassPathResource;
import cokr.xit.foundation.Downloadable;
public class PDFWriter extends PDF {
public PDFWriter(){
@ -105,15 +110,29 @@ public class PDFWriter extends PDF {
return this;
}
public PDFWriter saveDocument(String path) throws IOException{
doc.save(path);
return this;
}
public PDFWriter closeDocument() throws IOException{
public void write(OutputStream out) {
try {
doc.save(out);
doc.close();
return this;
} catch (Exception e) {
throw runtimeException(e);
}
}
public File write(String filepath) {
File file = new File(filepath);
try (FileOutputStream out = new FileOutputStream(file)) {
write(out);
return file;
} catch (Exception e) {
throw runtimeException(e);
}
}
public Downloadable getDownloadable() {
return new Downloadable()
.setContentType(MIME_TYPE)
.setWriter(this::write);
}
}

@ -85,8 +85,8 @@ public class Advntce extends PDFPrintFormat {
super();
}
public Advntce(Print print, PrintOption printOption,
DataObject otptBscStng, List<DataObject> otptArtclStngList, String paperSeCd){
super(print,printOption,otptBscStng,otptArtclStngList,paperSeCd);
DataObject otptBscStng, List<DataObject> otptArtclStngList, String paperSeCd, List<DataObject> data){
super(print,printOption,otptBscStng,otptArtclStngList,paperSeCd, data);
this.print.setFormatKorName("사전통지서");
this.sndngSeCd = "02";
}

@ -95,8 +95,8 @@ public class Nht extends PDFPrintFormat {
}
public Nht(Print print, PrintOption printOption,
DataObject otptBscStng, List<DataObject> otptArtclStngList, String paperSeCd) {
super(print,printOption,otptBscStng,otptArtclStngList,paperSeCd);
DataObject otptBscStng, List<DataObject> otptArtclStngList, String paperSeCd, List<DataObject> data) {
super(print,printOption,otptBscStng,otptArtclStngList,paperSeCd, data);
this.print.setFormatKorName("고지서");
this.sndngSeCd = "03";
}

@ -36,6 +36,8 @@ public abstract class PDFPrintFormat {
protected Print print;
protected PrintOption printOption;
protected List<DataObject> data;
protected DataObject otptBscStng;
protected List<DataObject> otptArtclStngList;
protected String paperSeCd;
@ -48,9 +50,9 @@ public abstract class PDFPrintFormat {
}
public PDFPrintFormat(Print print, PrintOption printOption,
DataObject otptBscStng, List<DataObject> otptArtclStngList, String paperSeCd) {
DataObject otptBscStng, List<DataObject> otptArtclStngList, String paperSeCd, List<DataObject> data) {
initDefaultStng();
this.data = data;
this.print = print;
this.print.setExtension("pdf");
this.printOption = printOption;
@ -225,14 +227,11 @@ public abstract class PDFPrintFormat {
return result;
}
public Map<String, Object> makePdfFile(List<DataObject> dataObjectList) {
public Map<String, Object> makeFile() {
Map<String, Object> result = new HashMap<>();
PDFWriter writer = new PDFWriter();
String resultFilePath = this.print.pathForNewFile();
//폰트 로드
Map<String, PDType0Font> fontMap = this.getFontMap(writer);
@ -274,7 +273,7 @@ public abstract class PDFPrintFormat {
rprsCrdnPhotoYn = true;
}
for(DataObject dataObject : dataObjectList) {
for(DataObject dataObject : data) {
writer.beginPage();
boolean completeFoldLine = false;
@ -448,13 +447,10 @@ public abstract class PDFPrintFormat {
} //출력자료건수 loop 끝
writer.saveDocument(resultFilePath);
writer.closeDocument();
String downloadFileName = this.print.getFormatKorName()+"_"+this.print.getPrintRequestDt()+".pdf";
result.put("filename", downloadFileName);
result.put("filePath", resultFilePath);
result.put("file", new File(resultFilePath));
result.put("download", writer.getDownloadable().setFilename(downloadFileName));
result.put("downloadData", data);
result.put("dataNames", this.filterDownloadDataNames());
} catch (Exception e) {
throw new RuntimeException("출력오류."+e);

@ -1783,12 +1783,10 @@ public class Sndb01Controller extends ApplicationController {
}
printOption.setGlobalVariable(globalVariable);
Advntce advntce = new Advntce(print,printOption,otptBscStng,otptArtclStngList,paperSeCd);
Map<String, Object> result = advntce.makePdfFile(dataObjectList);
Advntce pdfFormat = new Advntce(print,printOption,otptBscStng,otptArtclStngList,paperSeCd,dataObjectList);
Map<String, Object> result = pdfFormat.makeFile();
mav.addAllObjects(result);
mav.addObject("downloadData", dataObjectList);
mav.addObject("dataNames", advntce.filterDownloadDataNames());
return mav;
}

@ -773,12 +773,10 @@ public class Sprt01Controller extends ApplicationController {
}
printOption.setGlobalVariable(globalVariable);
Advntce advntce = new Advntce(print,printOption,otptBscStng,otptArtclStngList,paperSeCd);
Advntce pdfFormat = new Advntce(print,printOption,otptBscStng,otptArtclStngList,paperSeCd,dataObjectList);
Map<String, Object> result = advntce.makePdfFile(dataObjectList);
Map<String, Object> result = pdfFormat.makeFile();
mav.addAllObjects(result);
mav.addObject("downloadData", dataObjectList);
mav.addObject("dataNames", advntce.filterDownloadDataNames());
return mav;
}
@ -1007,12 +1005,10 @@ public class Sprt01Controller extends ApplicationController {
}
printOption.setGlobalVariable(globalVariable);
Nht nht = new Nht(print,printOption,otptBscStng,otptArtclStngList,paperSeCd);
Nht pdfFormat = new Nht(print,printOption,otptBscStng,otptArtclStngList,paperSeCd,dataObjectList);
Map<String, Object> result = nht.makePdfFile(dataObjectList);
Map<String, Object> result = pdfFormat.makeFile();
mav.addAllObjects(result);
mav.addObject("downloadData", dataObjectList);
mav.addObject("dataNames", nht.filterDownloadDataNames());
return mav;
}

Loading…
Cancel
Save