사전통보서 출력시 사진갯수에 따른 이미지크기 및 위치 수정 기능 추가

main
이범준 11 months ago
parent a1e319ab84
commit fab0d51e63

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

@ -38,6 +38,13 @@ public abstract class PDFFormat {
return new DefaultOtptArtclStng("image", otptArtclNm, dscrp, otptBscVl);
}
/**
* .
*/
public DefaultOtptArtclStng images(String otptArtclNm, String dscrp, String otptBscVl){
return new DefaultOtptArtclStng("images", otptArtclNm, dscrp, otptBscVl);
}
/**
* .
*/
@ -62,6 +69,9 @@ public abstract class PDFFormat {
public abstract String getMappingValue(String otptArtclNm, String defaultValue, boolean forPost,
DataObject dataObject, PrintOption printOption, PDFPrintUtil pdfPrintUtil);
public abstract List<String> getMappingValues(String otptArtclNm, String defaultValue, boolean forPost,
DataObject dataObject, PrintOption printOption, PDFPrintUtil pdfPrintUtil);
/**
* .
*/
@ -93,4 +103,6 @@ public abstract class PDFFormat {
public abstract DataObject createSampleData();
}

@ -5,6 +5,7 @@ import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.apache.pdfbox.pdmodel.PDDocument;
@ -228,13 +229,144 @@ public class PDFPrintUtil extends PrintUtil {
try {
if(!imagePath.equals("")) {
PDImageXObject image = PDImageXObject.createFromFile(imagePath, doc);
contentStream.drawImage(image, xyAbsolute[0], xyAbsolute[1], size[0], size[1]);
contentStream.drawImage(image, xyAbsolute[0], xyAbsolute[1]-size[1], size[0], size[1]);
}
} catch (IOException e) {
throw new RuntimeException("PDF 파일 출력 중 오류가 발생하였습니다.");
}
}
public List<PstnAndSize> devideImageArea(float[] totAreaPstn, float[] totAreaSize, int imageCntSetting, int dataImageCnt) {
List<PstnAndSize> result = new ArrayList<PstnAndSize>();
int printable = imageCntSetting <= dataImageCnt ? imageCntSetting : dataImageCnt;
if(printable <= 1) {
result.add(new PstnAndSize(totAreaPstn[0], totAreaPstn[1], totAreaSize[0], totAreaSize[1]));
return result;
}
boolean longerThenWidth = totAreaSize[1] > totAreaSize[0];
int xLengthOfD2 = 0;
int yLengthOfD2 = 0;
if(printable == 2){
if(longerThenWidth) {
xLengthOfD2 = 1;
yLengthOfD2 = 2;
} else {
xLengthOfD2 = 2;
yLengthOfD2 = 1;
}
} else if(printable == 3 || printable == 4){
xLengthOfD2 = 2;
yLengthOfD2 = 2;
} else if(printable == 5 || printable == 6){
if(longerThenWidth) {
xLengthOfD2 = 2;
yLengthOfD2 = 3;
} else {
xLengthOfD2 = 3;
yLengthOfD2 = 2;
}
} else {
throw new RuntimeException("PDF 파일 출력 중 오류가 발생하였습니다.");
}
PstnAndSize[][] d2Array = new PstnAndSize[xLengthOfD2][yLengthOfD2];
Size cellSize = new Size(totAreaSize[0] / (xLengthOfD2 * 1.0f), totAreaSize[1] / (yLengthOfD2 * 1.0f));
d2Array[0][0] = new PstnAndSize(totAreaPstn[0], totAreaPstn[1], cellSize.getWidth(), cellSize.getHeight());
d2Array = this.fillImageCells(d2Array);
//출력영역 크기 병합
if(printable == 3 || printable == 5) {
boolean longerThenWidth_cell = cellSize.getHeight() > cellSize.getWidth();
if(longerThenWidth_cell) {
d2Array = this.mergeLastImageCell(d2Array, "left");
} else {
d2Array = this.mergeLastImageCell(d2Array, "up");
}
}
for(int y=0; y < yLengthOfD2; y++) {
for(int x=0; x < xLengthOfD2; x++) {
if(d2Array[x][y] != null) {
result.add(d2Array[x][y]);
}
}
}
return result;
}
private PstnAndSize[][] fillImageCells(PstnAndSize[][] d2) {
int xLengthOfD2 = d2.length;
int yLengthOfD2 = d2[0].length;
PstnAndSize firstCell = d2[0][0];
Size cellSize = firstCell.getSize();
float cellWidth = cellSize.getWidth();
float cellHeight = cellSize.getHeight();
Pstn startPoint = firstCell.getPstn();
float spX = startPoint.getLeft();
float spY = startPoint.getTop();
for(int x=0; x < xLengthOfD2; x++) {
for(int y=0; y < yLengthOfD2; y++) {
if(x != 0 || y != 0) {
d2[x][y] = new PstnAndSize(spX + (cellWidth * (x * 1.0f)), spY + (cellHeight * (y * 1.0f)), cellSize);
}
}
}
return d2;
}
public PstnAndSize[][] mergeLastImageCell(PstnAndSize[][] d2, String mergeDirection) {
if(!mergeDirection.equals("up") && !mergeDirection.equals("left")) {
throw new RuntimeException("PDF 파일 출력 중 오류가 발생하였습니다.");
}
int xLengthOfD2 = d2.length;
int yLengthOfD2 = d2[0].length;
int lastCellIndexX = xLengthOfD2-1;
int lastCellIndexY = yLengthOfD2-1;
int mergeTargetCellIndexX = 0;
int mergeTargetCellIndexY = 0;
if(mergeDirection.equals("up")) {
mergeTargetCellIndexX = lastCellIndexX;
mergeTargetCellIndexY = lastCellIndexY-1;
}
if(mergeDirection.equals("left")) {
mergeTargetCellIndexX = lastCellIndexX-1;
mergeTargetCellIndexY = lastCellIndexY;
}
//병합대상셀
if(mergeDirection.equals("up")) {
d2[mergeTargetCellIndexX][mergeTargetCellIndexY] = (d2[mergeTargetCellIndexX][mergeTargetCellIndexY]).x2Height();
}
if(mergeDirection.equals("left")) {
d2[mergeTargetCellIndexX][mergeTargetCellIndexY] = (d2[mergeTargetCellIndexX][mergeTargetCellIndexY]).x2Width();
}
//마지막셀
d2[lastCellIndexX][lastCellIndexY] = null;
return d2;
}
/**
* pdf .
*/
public void renderFoldLine(PDPageContentStream contentStream, PDRectangle paper, String foldCode) {
if(foldCode.equals("") && !foldCode.equals("01") && !foldCode.equals("02")) {
return;
@ -372,4 +504,6 @@ public class PDFPrintUtil extends PrintUtil {
throw new RuntimeException("글꼴 로드 오류");
}
}
}

@ -13,4 +13,8 @@ public class Pstn {
private float left;
private float top;
public float[] to2Float() {
return new float[] { this.left, this.top };
}
}

@ -0,0 +1,61 @@
package cokr.xit.fims.cmmn.pdf;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class PstnAndSize {
public PstnAndSize(float left, float top, float width, float height){
this.left = left;
this.top = top;
this.width = width;
this.height = height;
}
public PstnAndSize(Pstn pstn, Size size){
this.left = pstn.getLeft();
this.top = pstn.getTop();
this.width = size.getWidth();
this.height = size.getHeight();
}
public PstnAndSize(Pstn pstn, float width, float height){
this.left = pstn.getLeft();
this.top = pstn.getTop();
this.width = width;
this.height = height;
}
public PstnAndSize(float left, float top, Size size){
this.left = left;
this.top = top;
this.width = size.getWidth();
this.height = size.getHeight();
}
private float left;
private float top;
private float width;
private float height;
public Pstn getPstn() {
return new Pstn(this.left, this.top);
}
public Size getSize() {
return new Size(this.width, this.height);
}
public float[] to4Float() {
return new float[] { this.left, this.top, this.width, this.height };
}
public PstnAndSize x2Width() {
this.width = this.width * 2.0f;
return this;
}
public PstnAndSize x2Height() {
this.height = this.height * 2.0f;
return this;
}
}

@ -0,0 +1,20 @@
package cokr.xit.fims.cmmn.pdf;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class Size {
public Size(float width, float height){
this.width = width;
this.height = height;
}
private float width;
private float height;
public float[] to2Float() {
return new float[] { this.width, this.height };
}
}

@ -1,5 +1,8 @@
package cokr.xit.fims.cmmn.pdf.format;
import java.util.ArrayList;
import java.util.List;
import cokr.xit.fims.cmmn.CmmnUtil;
import cokr.xit.fims.cmmn.FactionUtil;
import cokr.xit.fims.cmmn.pdf.PDFFormat;
@ -32,10 +35,8 @@ public class Advntce extends PDFFormat {
add(
image("background","배경이미지","").a4(0, 0).letter(0, 0).size(0, 0),
image("photo1","단속사진1","").a4(0, 0).letter(0, 0).size(0, 0),
image("photo2","단속사진2","").a4(0, 0).letter(0, 0).size(0, 0),
image("photo3","단속사진3","").a4(0, 0).letter(0, 0).size(0, 0),
image("photo4","단속사진4","").a4(0, 0).letter(0, 0).size(0, 0),
images("crdnPhoto","단속사진","").a4(110, 100).letter(116, 95).size(90, 80),
image("rprsCrdnPhoto","대표단속사진","").a4(10, 200).letter(10, 186).size(80, 80),
text("rtpyrNm","수신자명",""),
text("rtpyrNo","수신자번호",""),
@ -98,19 +99,9 @@ public class Advntce extends PDFFormat {
case "background" -> {
result = dataObject.string("");
}
case "photo1" -> {
case "rprsCrdnPhoto" -> { //대표사진
result = dataObject.string("CRDN_PHOTO1");
}
case "photo2" -> {
result = dataObject.string("CRDN_PHOTO2");
}
case "photo3" -> {
result = dataObject.string("CRDN_PHOTO3");
}
case "photo4" -> {
result = dataObject.string("CRDN_PHOTO4");
}
case "rtpyrNm" -> {
result = dataObject.string("RTPYR_NM");
}
@ -316,12 +307,34 @@ public class Advntce extends PDFFormat {
dataObject.put("VR_ACTNO10", "101010-00-000000");
dataObject.put("EPAY_NO", "00000-0-00-00-000000000");
dataObject.put("FFNLG_CRDN_AMT", "100000");
dataObject.put("CRDN_PHOTO1", "");
dataObject.put("CRDN_PHOTO2", "");
dataObject.put("CRDN_PHOTO3", "");
dataObject.put("CRDN_PHOTO4", "");
dataObject.put("CRDN_PHOTO1", "samplefiles/crdn1.png");
dataObject.put("CRDN_PHOTO2", "samplefiles/crdn2.png");
dataObject.put("CRDN_PHOTO3", "samplefiles/crdn3.png");
dataObject.put("CRDN_PHOTO4", "samplefiles/crdn4.png");
dataObject.put("CRDN_PHOTO5", "samplefiles/crdn5.png");
dataObject.put("CRDN_PHOTO6", "samplefiles/crdn6.png");
dataObject.put("CRDN_PHOTO7", "samplefiles/crdn7.png");
return dataObject;
}
@Override
public List<String> getMappingValues(String otptArtclNm, String defaultValue, boolean forPost,
DataObject dataObject, PrintOption printOption, PDFPrintUtil pdfPrintUtil) {
List<String> result = new ArrayList<String>();
switch(otptArtclNm) {
case "crdnPhoto" -> {
int i = 1;
while(!dataObject.string("CRDN_PHOTO"+i).equals("")) {
result.add(dataObject.string("CRDN_PHOTO"+i));
i++;
}
}
}
return result;
}
}

@ -33,6 +33,7 @@ import cokr.xit.fims.cmmn.hwp.format.RequestForDelivery;
import cokr.xit.fims.cmmn.pdf.DefaultOtptArtclStng;
import cokr.xit.fims.cmmn.pdf.PDFFormat;
import cokr.xit.fims.cmmn.pdf.PDFPrintUtil;
import cokr.xit.fims.cmmn.pdf.PstnAndSize;
import cokr.xit.fims.cmmn.pdf.format.Advntce;
import cokr.xit.fims.cmmn.service.bean.FactionBean;
import cokr.xit.fims.cmmn.service.bean.StngBean;
@ -284,6 +285,24 @@ public class Sprt01ServiceBean extends AbstractServiceBean implements Sprt01Serv
SprtQuery sprtQuery = new SprtQuery();
sprtQuery.setCrdnIDs(crdnIds);
dataObjectList = integrationSearchMapper.selectIntegrationDataList(sprtQuery);
for(int i=0; i < dataObjectList.size(); i++) {
DataObject dataObject = dataObjectList.get(i);
String crndId = dataObject.string("CRDN_ID");
FileQuery fileQuery = new FileQuery();
fileQuery.setInfoType(Crdn.INF_TYPE);
fileQuery.setInfoKeys(crndId);
List<DataObject> fileInfoList = fileBean.getFileList(fileQuery);
if(fileInfoList != null && fileInfoList.size() > 0) {
for(int j=0; j<fileInfoList.size(); j++) {
dataObject.set("CRDN_PHOTO"+(j+1), fileInfoList.get(j).string("URL"));
}
}
}
}
DataObject userStngInfo = stngBean.getStng("user");
@ -353,23 +372,30 @@ public class Sprt01ServiceBean extends AbstractServiceBean implements Sprt01Serv
//출력 요소별 설정
List<DataObject> otptArtclStngList = otptStngMapper.selectOtptArtclStngList(otptStngQuery);
//출력요소별 속성 정보 추가
pdfFormat.appendOtptAttribute(otptArtclStngList);
//출력 요소 정렬
Comparator<DataObject> comparator1 = (item1, item2) -> {
int int1 = item1.string("UNIQUE_YN").equals("Y") ? 0 : 1;
int int2 = item2.string("UNIQUE_YN").equals("Y") ? 0 : 1;
return Integer.compare(int1, int2);
};
Comparator<DataObject> comparator2 = (item1, item2) -> {
int int1 = item1.number("OTPT_ARTCL_ORDR").intValue();
int int2 = item2.number("OTPT_ARTCL_ORDR").intValue();
return Integer.compare(int1, int2);
};;
};
otptArtclStngList = otptArtclStngList.stream()
.sorted(comparator1.thenComparing(comparator2)).collect(Collectors.toList());
//대표단속사진 설정 여부 확인
boolean rprsCrdnPhotoYn = false;
if(otptArtclStngList.stream().filter(item -> item.string("OTPT_ARTCL_NM").equals("rprsCrdnPhoto")).count() > 0) {
rprsCrdnPhotoYn = true;
}
for(DataObject dataObject : dataObjectList) {
//페이지생성(건별)
PDPage blankPage = new PDPage(paper);
@ -421,6 +447,33 @@ public class Sprt01ServiceBean extends AbstractServiceBean implements Sprt01Serv
pdfPrintUtil.insertImage(doc, contentStream, imagePath, pstn, size);
} else if(prototypeStng.getComponentType().equals("images")) {
List<String> imagePaths = pdfFormat.getMappingValues(otptArtclNm,defaultValue,forPost,dataObject,printOption,pdfPrintUtil);
if(otptArtclNm.equals("crdnPhoto")) {
if(rprsCrdnPhotoYn) {
imagePaths.remove(0);
}
}
int printCntSetting = otptBscStng.number("OTPT_PHOTO_CNT").intValue();
int dataImageCnt = imagePaths.size();
if(printCntSetting != 0 && dataImageCnt != 0) {
List<PstnAndSize> devideInfos = pdfPrintUtil.devideImageArea(pstn, size, printCntSetting, dataImageCnt);
for (int i=0; i< devideInfos.size(); i++){
PstnAndSize devideInfo = devideInfos.get(i);
pdfPrintUtil.insertImage(doc, contentStream,
imagePaths.get(i), devideInfo.getPstn().to2Float(), devideInfo.getSize().to2Float());
}
}
}
}

@ -248,7 +248,7 @@
<template id="photoCntTemplate--${pageName}">
<span class="px-2">
<label class="col-form-label bg-lighter px-2">사진 출력</label>
<label class="col-form-label bg-lighter px-2">사진 출력 영역</label>
<input type="number" name="otptPhotoCnt" class="form-control w-px-50" min="0" max="6" /> 장
</span>
</template>

Loading…
Cancel
Save