pdf출력 수정

main
이범준 12 months ago
parent c8fef50c00
commit 66e44dbe3c

@ -0,0 +1,85 @@
package cokr.xit.fims.cmmn.pdf;
import cokr.xit.fims.cmmn.pdf.format.Pstn;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class DefaultOtptStng {
public DefaultOtptStng(String contentType, String otptNm, String colNm, String otptBscVl){
this.contentType = contentType;
this.otptNm=otptNm;
this.colNm=colNm;
this.otptBscVl=otptBscVl;
this.widthSz=0;
this.heightSz=0;
this.fontNm="gulim";
this.fontSize=10;
this.fontColor="BLACK";
this.fontStyle="FILL";
}
public DefaultOtptStng a4(float leftPstn, float topPstn) {
this.a4 = new Pstn(leftPstn, topPstn);
return this;
}
public DefaultOtptStng letter(float leftPstn, float topPstn) {
this.letter = new Pstn(leftPstn, topPstn);
return this;
}
public DefaultOtptStng size(float width, float height) {
this.widthSz = width;
this.heightSz = height;
return this;
}
public DefaultOtptStng font(String fontNm, int fontSize, String fontColor, String fontStyle) {
this.fontNm = fontNm;
this.fontSize = fontSize;
this.fontColor = fontColor;
this.fontStyle = fontStyle;
return this;
}
public float getLeftPstn(String paper) {
switch (paper) {
case "01": {
return this.getA4().getLeft();
}
case "02": {
return this.getLetter().getLeft();
}
}
return 0;
}
public float getTopPstn(String paper) {
switch (paper) {
case "01": {
return this.getA4().getTop();
}
case "02": {
return this.getLetter().getTop();
}
}
return 0;
}
private String contentType;
private String otptNm;
private String colNm;
private String otptBscVl;
private Pstn a4;
private Pstn letter;
private float widthSz;
private float heightSz;
private String fontNm;
private int fontSize;
private String fontColor;
private String fontStyle;
}

@ -0,0 +1,43 @@
package cokr.xit.fims.cmmn.pdf;
import java.lang.reflect.Field;
import org.apache.pdfbox.pdmodel.graphics.color.PDColor;
import org.apache.pdfbox.pdmodel.graphics.color.PDDeviceRGB;
public class PDFColors {
public static final PDColor RED = new PDColor(new float[] { 1, 0, 0 }, PDDeviceRGB.INSTANCE);
public static final PDColor ORANGE = new PDColor(new float[] { 1, 0.502f, 0 }, PDDeviceRGB.INSTANCE);
public static final PDColor YELLOW = new PDColor(new float[] { 1, 1, 0 }, PDDeviceRGB.INSTANCE);
public static final PDColor YELLOW_GREEN = new PDColor(new float[] { 0.502f, 1, 0 }, PDDeviceRGB.INSTANCE);
public static final PDColor GREEN = new PDColor(new float[] { 0, 1, 0 }, PDDeviceRGB.INSTANCE);
public static final PDColor GREEN_CYAN = new PDColor(new float[] { 0, 1, 0.502f }, PDDeviceRGB.INSTANCE);
public static final PDColor CYAN = new PDColor(new float[] { 0, 1, 1 }, PDDeviceRGB.INSTANCE);
public static final PDColor CYAN_BLUE = new PDColor(new float[] { 0, 0.502f, 1 }, PDDeviceRGB.INSTANCE);
public static final PDColor BLUE = new PDColor(new float[] { 0, 1, 0 }, PDDeviceRGB.INSTANCE);
public static final PDColor VIOLET = new PDColor(new float[] { 0.502f, 1, 0 }, PDDeviceRGB.INSTANCE);
public static final PDColor MAGENTA = new PDColor(new float[] { 1, 1, 0 }, PDDeviceRGB.INSTANCE);
public static final PDColor DEEP_PINK = new PDColor(new float[] { 1, 0.502f, 0 }, PDDeviceRGB.INSTANCE);
public static final PDColor WHITE = new PDColor(new float[] { 1, 1, 1 }, PDDeviceRGB.INSTANCE);
public static final PDColor LIGHT_GREY = new PDColor(new float[] { 0.753f, 0.753f, 0.753f }, PDDeviceRGB.INSTANCE);
public static final PDColor GREY = new PDColor(new float[] { 0.627f, 0.627f, 0.627f }, PDDeviceRGB.INSTANCE);
public static final PDColor DARK_GREY = new PDColor(new float[] { 0.376f, 0.376f, 0.376f }, PDDeviceRGB.INSTANCE);
public static final PDColor BLACK = new PDColor(new float[] { 0, 0, 0 }, PDDeviceRGB.INSTANCE);
public static PDColor getColor(String colorName) {
try {
Field field = PDFColors.class.getDeclaredField(colorName);
if(field == null) {
return BLACK;
}
field.setAccessible(true);
PDColor value = (PDColor)field.get(PDFColors.class);
return value;
} catch (Exception e) {
throw new RuntimeException("색상 설정 오류");
}
}
}

@ -0,0 +1,28 @@
package cokr.xit.fims.cmmn.pdf;
import java.util.ArrayList;
import java.util.List;
public class PDFFormat {
protected List<DefaultOtptStng> defaultOtptStng = new ArrayList<DefaultOtptStng>();
public List<DefaultOtptStng> getDefaultOtptStng(){
return this.defaultOtptStng;
}
public DefaultOtptStng text(String otptNm, String colNm, String otptBscVl){
return new DefaultOtptStng("text", otptNm, colNm, otptBscVl);
}
public DefaultOtptStng image(String otptNm, String colNm){
return new DefaultOtptStng("image" ,otptNm, colNm, "");
}
public void add(DefaultOtptStng... defaultOtptStngs){
for(DefaultOtptStng defaultOtptStng : defaultOtptStngs) {
this.defaultOtptStng.add(defaultOtptStng);
}
}
}

@ -1,16 +1,20 @@
package cokr.xit.fims.cmmn.pdf; package cokr.xit.fims.cmmn.pdf;
import java.awt.Color;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.Map;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.apache.pdfbox.pdmodel.font.PDType0Font; import org.apache.pdfbox.pdmodel.font.PDType0Font;
import org.apache.pdfbox.pdmodel.graphics.color.PDColor;
import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject;
import org.apache.pdfbox.pdmodel.graphics.state.RenderingMode; import org.apache.pdfbox.pdmodel.graphics.state.RenderingMode;
import cokr.xit.fims.cmmn.PrintUtil; import cokr.xit.fims.cmmn.PrintUtil;
import cokr.xit.foundation.data.DataObject;
public class PDFPrintUtil extends PrintUtil { public class PDFPrintUtil extends PrintUtil {
@ -62,10 +66,11 @@ public class PDFPrintUtil extends PrintUtil {
// //
public void writeText(PDPageContentStream contentStream, String text, float[] XYmm, public void writeText(PDPageContentStream contentStream, String text, float[] XYmm,
PDType0Font font, int fontSize, RenderingMode fontStyle, Color fontColor) { PDType0Font font, int fontSize, RenderingMode fontStyle, PDColor fontColor) {
try { try {
float[] xyOffset = this.toPDFCoordinate(XYmm).offset(); float[] xyAbsolute = this.toPDFCoordinate(XYmm).absolute();
contentStream.beginText(); contentStream.beginText();
contentStream.setFont(font, fontSize); contentStream.setFont(font, fontSize);
@ -73,7 +78,8 @@ public class PDFPrintUtil extends PrintUtil {
contentStream.setNonStrokingColor(fontColor); contentStream.setNonStrokingColor(fontColor);
contentStream.newLineAtOffset(xyOffset[0], xyOffset[1]); contentStream.newLineAtOffset(xyAbsolute[0], xyAbsolute[1]);
contentStream.showText(text); contentStream.showText(text);
contentStream.endText(); contentStream.endText();
@ -83,13 +89,28 @@ public class PDFPrintUtil extends PrintUtil {
} }
public void insertImage(PDDocument doc, PDPageContentStream contentStream, String imagePath, float[] XYmm,
float[] SIZEmm) {
float[] xyAbsolute = this.toPDFCoordinate(XYmm).absolute();
float[] size = this.toPDFCoordinate(SIZEmm).offset();
try {
if(!imagePath.equals("")) {
PDImageXObject image = PDImageXObject.createFromFile(imagePath, doc);
contentStream.drawImage(image, xyAbsolute[0], xyAbsolute[1], size[0], size[1]);
}
} catch (IOException e) {
throw new RuntimeException("PDF 파일 출력 중 오류가 발생하였습니다.");
}
}
public void renderFoldLine(PDPageContentStream contentStream, float paperWidth, float paperHeight) { public void renderFoldLine(PDPageContentStream contentStream, float paperWidth, float paperHeight) {
float foldHeight = 712/3; float foldHeight = 712/3;
float bottomFold = foldHeight; //하단접는곳 float bottomFold = foldHeight; //하단접는곳
float topFold = foldHeight * 2; //상단접는곳 float topFold = foldHeight * 2; //상단접는곳
if(paperHeight == 842f) { if(paperHeight == 841.8898f) {
bottomFold += 130f; bottomFold += 130f;
topFold += 130f; topFold += 130f;
} }
@ -107,4 +128,97 @@ public class PDFPrintUtil extends PrintUtil {
throw new RuntimeException("PDF 파일 출력 중 오류가 발생하였습니다."); throw new RuntimeException("PDF 파일 출력 중 오류가 발생하였습니다.");
} }
} }
public PDType0Font getFontStng(DefaultOtptStng defaultStng, DataObject sggStng, Map<String, PDType0Font> fontMap) {
if(sggStng != null && !sggStng.isEmpty() && !sggStng.string("FONT_NM").equals("")) {
return fontMap.get(sggStng.string("FONT_NM"));
} else {
return fontMap.get(defaultStng.getFontNm());
}
}
public float[] getPstnStng(DefaultOtptStng defaultStng, DataObject sggStng, String otptPaperSeCd) {
if(sggStng != null && !sggStng.isEmpty()) {
return new float[] {
sggStng.number("LEFT_PSTN").floatValue(),
sggStng.number("TOP_PSTN").floatValue()
};
} else {
return new float[] {
defaultStng.getLeftPstn(otptPaperSeCd),
defaultStng.getTopPstn(otptPaperSeCd)
};
}
}
public int getFontSize(DefaultOtptStng defaultStng, DataObject sggStng) {
if(sggStng != null && !sggStng.isEmpty() && !sggStng.string("FONT_SIZE").equals("")) {
return sggStng.number("FONT_SIZE").intValue();
} else {
return defaultStng.getFontSize();
}
}
public RenderingMode getFontStyle(DefaultOtptStng defaultStng, DataObject sggStng) {
if(sggStng != null && !sggStng.isEmpty() && !sggStng.string("FONT_STYLE").equals("")) {
return RenderingMode.valueOf(sggStng.string("FONT_STYLE"));
} else {
return RenderingMode.valueOf(defaultStng.getFontStyle());
}
}
public PDColor getFontColor(DefaultOtptStng defaultStng, DataObject sggStng) {
if(sggStng != null && !sggStng.isEmpty() && !sggStng.string("FONT_COLOR").equals("")) {
return PDFColors.getColor(sggStng.string("FONT_COLOR"));
} else {
return PDFColors.getColor(defaultStng.getFontColor());
}
}
public String getTextValue(DefaultOtptStng defaultStng, DataObject sggStng, DataObject dataObject) {
String textValue = "";
if(sggStng != null && !sggStng.isEmpty() && !sggStng.string("COL_NM").equals("")) {
textValue = dataObject.string(sggStng.string("COL_NM"));
if(textValue.equals("")) {
textValue = sggStng.string("OTPT_BSC_VL");
}
} else {
textValue = dataObject.string(defaultStng.getColNm());
if(textValue.equals("")) {
textValue = defaultStng.getOtptBscVl();
}
}
return textValue;
}
public String getImagePath(DefaultOtptStng defaultStng, DataObject sggStng, DataObject dataObject) {
if(sggStng != null && !sggStng.isEmpty() && !sggStng.string("COL_NM").equals("")) {
return dataObject.string(sggStng.string("COL_NM"));
} else {
return dataObject.string(defaultStng.getColNm());
}
}
public float[] getSize(DefaultOtptStng defaultStng, DataObject sggStng) {
if(sggStng != null && !sggStng.isEmpty()) {
return new float[] {
sggStng.number("LEFT_PSTN").floatValue(),
sggStng.number("TOP_PSTN").floatValue()
};
} else {
return new float[] {
defaultStng.getWidthSz(),
defaultStng.getHeightSz()
};
}
}
} }

@ -1,5 +1,20 @@
package cokr.xit.fims.cmmn.pdf.format; package cokr.xit.fims.cmmn.pdf.format;
public class Advntce { import cokr.xit.fims.cmmn.pdf.PDFFormat;
/**
*
*/
public class Advntce extends PDFFormat {
public Advntce(){
add(
text("CRDN_YMD","CRDN_YMD","").a4(105, 150).letter(0, 0),
text("VHRNO","VHRNO","").a4(30, 30).letter(0, 0)
//image("OFFCS1","OFFCS").a4(0, 0).letter(0, 0).size(0, 0),
//image("OFFCS2","OFFCS").a4(0, 0).letter(0, 0).size(0, 0),
//image("OFFCS3","OFFCS").a4(0, 0).letter(0, 0).size(0, 0)
);
}
} }

@ -0,0 +1,16 @@
package cokr.xit.fims.cmmn.pdf.format;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class Pstn {
public Pstn(float left, float top){
this.left = left;
this.top = top;
}
private float left;
private float top;
}

@ -1,11 +1,11 @@
package cokr.xit.fims.sprt.service.bean; package cokr.xit.fims.sprt.service.bean;
import java.awt.Color;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -14,6 +14,7 @@ import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.PDPageContentStream; import org.apache.pdfbox.pdmodel.PDPageContentStream;
import org.apache.pdfbox.pdmodel.common.PDRectangle; import org.apache.pdfbox.pdmodel.common.PDRectangle;
import org.apache.pdfbox.pdmodel.font.PDType0Font; import org.apache.pdfbox.pdmodel.font.PDType0Font;
import org.apache.pdfbox.pdmodel.graphics.color.PDColor;
import org.apache.pdfbox.pdmodel.graphics.state.RenderingMode; import org.apache.pdfbox.pdmodel.graphics.state.RenderingMode;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -28,7 +29,10 @@ import cokr.xit.fims.cmmn.hwp.format.CrdnList;
import cokr.xit.fims.cmmn.hwp.format.RcvmtConfirm; import cokr.xit.fims.cmmn.hwp.format.RcvmtConfirm;
import cokr.xit.fims.cmmn.hwp.format.ReportOnClaims; import cokr.xit.fims.cmmn.hwp.format.ReportOnClaims;
import cokr.xit.fims.cmmn.hwp.format.RequestForDelivery; import cokr.xit.fims.cmmn.hwp.format.RequestForDelivery;
import cokr.xit.fims.cmmn.pdf.DefaultOtptStng;
import cokr.xit.fims.cmmn.pdf.PDFFormat;
import cokr.xit.fims.cmmn.pdf.PDFPrintUtil; import cokr.xit.fims.cmmn.pdf.PDFPrintUtil;
import cokr.xit.fims.cmmn.pdf.format.Advntce;
import cokr.xit.fims.cmmn.service.bean.FactionBean; import cokr.xit.fims.cmmn.service.bean.FactionBean;
import cokr.xit.fims.cmmn.service.bean.StngBean; import cokr.xit.fims.cmmn.service.bean.StngBean;
import cokr.xit.fims.crdn.Crdn; import cokr.xit.fims.crdn.Crdn;
@ -60,6 +64,8 @@ import kr.dogfoot.hwplib.writer.HWPWriter;
@Service("sprt01Service") @Service("sprt01Service")
public class Sprt01ServiceBean extends AbstractServiceBean implements Sprt01Service { public class Sprt01ServiceBean extends AbstractServiceBean implements Sprt01Service {
private Object object;
/** 업무지원 Bean */ /** 업무지원 Bean */
@Resource(name="sprt01Bean") @Resource(name="sprt01Bean")
protected Sprt01Bean sprt01Bean; protected Sprt01Bean sprt01Bean;
@ -318,10 +324,19 @@ public class Sprt01ServiceBean extends AbstractServiceBean implements Sprt01Serv
if(formatName.equals("advntce")) { if(formatName.equals("advntce")) {
sndngSeCd = "02"; sndngSeCd = "02";
} }
PDFFormat pdfFormat = null;
if(formatName.equals("advntce")) {
pdfFormat = new Advntce();
}
List<DefaultOtptStng> predefinedList = pdfFormat.getDefaultOtptStng();
otptStngQuery.setSndngSeCd(sndngSeCd); otptStngQuery.setSndngSeCd(sndngSeCd);
otptStngQuery.setOtptPaperSeCd(otptPaperSeCd); otptStngQuery.setOtptPaperSeCd(otptPaperSeCd);
List<DataObject> otptStng = otptStngMapper.selectOtptStngList(otptStngQuery); List<DataObject> otptStng = otptStngMapper.selectOtptStngList(otptStngQuery);
Map<String, DataObject> byOtptItemStng = otptStng.stream()
.collect(Collectors.toMap((item) -> item.string("OTPT_NM"), (item) -> item));
for(DataObject dataObject : dataObjectList) { for(DataObject dataObject : dataObjectList) {
//페이지생성(건별) //페이지생성(건별)
@ -333,72 +348,35 @@ public class Sprt01ServiceBean extends AbstractServiceBean implements Sprt01Serv
// 컨텐츠 스트림 열기 // 컨텐츠 스트림 열기
PDPageContentStream contentStream = new PDPageContentStream(doc, page); PDPageContentStream contentStream = new PDPageContentStream(doc, page);
//접는곳 점선 그리기 //접는곳 점선 그리기
pdfPrintUtil.renderFoldLine(contentStream, paperWidth, paperHeight); pdfPrintUtil.renderFoldLine(contentStream, paperWidth, paperHeight);
//이미지 그리기 for(DefaultOtptStng predefined : predefinedList) {
//단속 이미지 로드(건별)
//PDImageXObject crdnPhotoImage = PDImageXObject.createFromFile("samplefiles/sample.JPG", doc);
//float photosXstart;
//float photosYstart;
//float photosXend;
//float photosYend;
//단속사진
//contentStream.drawImage(crdnPhotoImage, 300, 280, 250, 280);
//사각형(모자이크)
//contentStream.addRect(0, 0, 0, 0);
DataObject otptItemStng = byOtptItemStng.get(predefined.getOtptNm());
//직인 float[] pstn = pdfPrintUtil.getPstnStng(predefined, otptItemStng, otptPaperSeCd);
//float[] offcsLocation = {300, 50};
//float offcsSize = 20;
//contentStream.drawImage(offcsImage, offcsLocation[0], offcsLocation[1], offcsSize, offcsSize);
//지자체로고 if(predefined.getContentType().equals("text")) {
//contentStream.drawImage(logoImage, ?, ?, logoWidth, logoHeight);
//배경 이미지
//contentStream.drawImage(pdImage, 0, 0, paperWidth, paperHeight);
String textValue = pdfPrintUtil.getTextValue(predefined, otptItemStng, dataObject);
PDType0Font font = pdfPrintUtil.getFontStng(predefined, otptItemStng, fontMap);
int fontSz = pdfPrintUtil.getFontSize(predefined, otptItemStng);
RenderingMode fontStyle = pdfPrintUtil.getFontStyle(predefined, otptItemStng);
PDColor fontColor = pdfPrintUtil.getFontColor(predefined, otptItemStng);
pdfPrintUtil.writeText(contentStream, textValue, pstn, font, fontSz, fontStyle, fontColor);
for(DataObject otptItemStng : otptStng) { } else if(predefined.getContentType().equals("image")) {
String otptNm = otptItemStng.string("OTPT_NM"); String imagePath = pdfPrintUtil.getImagePath(predefined, otptItemStng, dataObject);
float[] size = pdfPrintUtil.getSize(predefined, otptItemStng);
pdfPrintUtil.insertImage(doc, contentStream, imagePath, pstn, size);
String dataValue = dataObject.string(otptItemStng.string("COL_NM"));
if(dataValue.equals("")) {
dataValue = otptItemStng.string("OTPT_BSC_VL");
} }
float[] pstn = new float[] {
otptItemStng.number("LEFT_PSTN").floatValue(),
otptItemStng.number("TOP_PSTN").floatValue()
};
PDType0Font font = fontMap.get("gulim");
if(!otptItemStng.string("FONT_NM").equals("")) {
font = fontMap.get(otptItemStng.string("FONT_NM"));
}
int fontSz = 10;
if(otptItemStng.number("FONT_SIZE").intValue() != 0) {
fontSz = otptItemStng.number("FONT_SIZE").intValue();
}
RenderingMode fontStyle = RenderingMode.valueOf("FILL");
if(!otptItemStng.string("FONT_STYLE").equals("")) {
fontStyle = RenderingMode.valueOf(otptItemStng.string("FONT_STYLE"));
}
Color fontColor = Color.getColor("BLACK");
if(!otptItemStng.string("FONT_COLOR").equals("")) {
fontColor = Color.getColor(otptItemStng.string("FONT_COLOR"));
}
pdfPrintUtil.writeText(contentStream, dataValue, pstn, font, fontSz, fontStyle, fontColor);
} }
contentStream.close(); contentStream.close();

@ -2,7 +2,7 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cokr.xit.fims.sprt.dao.OtptStngMapper"> <mapper namespace="cokr.xit.fims.sprt.dao.OtptStngMapper">
<select id="" parameterType="cokr.xit.fims.sprt.OtptStngQuery" resultType="dataobject"> <select id="selectOtptStngList" parameterType="cokr.xit.fims.sprt.OtptStngQuery" resultType="dataobject">
/* 출력 설정 조회(otptStngMapper.selectOtptStngList) */ /* 출력 설정 조회(otptStngMapper.selectOtptStngList) */
SELECT OTPT_FORM_ID SELECT OTPT_FORM_ID
, SGG_CD , SGG_CD

Loading…
Cancel
Save