샘플파일 경로 수정

main
이범준 10 months ago
parent 2cc5060d0c
commit e633d20369

@ -4,6 +4,7 @@ import java.awt.Graphics2D;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
@ -105,7 +106,7 @@ public class CmmnUtil {
* @param source , target , mosaicInfos * @param source , target , mosaicInfos
* @return * @return
*/ */
public static void createMaskedImage(File source, File target, List<DataObject> mosaicInfos) { public static void createMaskedImage(InputStream source, File target, List<DataObject> mosaicInfos) {
BufferedImage buffer_black_image = new BufferedImage(1, 1, BufferedImage.TYPE_3BYTE_BGR); BufferedImage buffer_black_image = new BufferedImage(1, 1, BufferedImage.TYPE_3BYTE_BGR);
String extension = FilenameUtils.getExtension(target.getName()); String extension = FilenameUtils.getExtension(target.getName());

@ -2,6 +2,7 @@ package cokr.xit.fims.cmmn.pdf.print;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
@ -223,7 +224,7 @@ public class PDFPrintUtil extends PrintUtil {
/** /**
* pdf . * pdf .
*/ */
public void insertImage(PDDocument doc, PDPageContentStream contentStream, String imagePath, float[] XYmm, public void insertImage(PDDocument doc, PDPageContentStream contentStream, InputStream imageStream, float[] XYmm,
float[] SIZEmm) { float[] SIZEmm) {
float[] xyAbsolute = this.toPDFCoordinate(XYmm).absolute(); float[] xyAbsolute = this.toPDFCoordinate(XYmm).absolute();
@ -232,10 +233,10 @@ public class PDFPrintUtil extends PrintUtil {
mmToPt(SIZEmm[0]),mmToPt(SIZEmm[1]) mmToPt(SIZEmm[0]),mmToPt(SIZEmm[1])
}; };
try { try {
if(!imagePath.equals("")) {
PDImageXObject image = PDImageXObject.createFromFile(imagePath, doc); PDImageXObject image = PDImageXObject.createFromByteArray(doc, imageStream.readAllBytes(), "temp");
contentStream.drawImage(image, xyAbsolute[0], xyAbsolute[1]-size[1], size[0], size[1]); contentStream.drawImage(image, xyAbsolute[0], xyAbsolute[1]-size[1], size[0], size[1]);
}
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
throw new RuntimeException("PDF 파일 출력 중 오류가 발생하였습니다."+e); throw new RuntimeException("PDF 파일 출력 중 오류가 발생하였습니다."+e);

@ -2,6 +2,7 @@ package cokr.xit.fims.sprt.service.bean;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -466,27 +467,50 @@ public class IntegrationSearchServiceBean extends AbstractServiceBean implements
} else if(prototypeStng.getComponentType().equals("image")) { } else if(prototypeStng.getComponentType().equals("image")) {
String imagePath = pdfFormat.getMappingValue(otptArtclNm,defaultValue,forPost,dataObject,printOption,pdfPrintUtil); String imagePath = pdfFormat.getMappingValue(otptArtclNm,defaultValue,forPost,dataObject,printOption,pdfPrintUtil);
if(ifEmpty(imagePath, ()->"").equals("")) {
continue;
}
InputStream is = null;
if(imagePath.startsWith("files")) {
File imageFile = new File(imagePath);
is = new FileInputStream(imageFile);
} else {
is = new ClassPathResource(imagePath).getInputStream();
}
String imageKey = ""; String imageKey = "";
if(otptArtclNm.equals("rprsCrdnPhoto")) { if(otptArtclNm.equals("rprsCrdnPhoto")) {
imageKey = pdfFormat.getMappingValue(otptArtclNm+"Key",defaultValue,forPost,dataObject,printOption,pdfPrintUtil); imageKey = pdfFormat.getMappingValue(otptArtclNm+"Key",defaultValue,forPost,dataObject,printOption,pdfPrintUtil);
} }
pdfPrintUtil.insertImage(doc, contentStream, imagePath, pstn, size); pdfPrintUtil.insertImage(doc, contentStream, is, pstn, size);
if(otptArtclNm.equals("rprsCrdnPhoto") && !imageKey.equals("")) { if(otptArtclNm.equals("rprsCrdnPhoto") && !imageKey.equals("")) {
String blackImage = "samplefiles/black.png";
InputStream is0 = null;
if(imagePath.startsWith("files")) {
File imageFile0 = new File(imagePath);
is0 = new FileInputStream(imageFile0);
} else {
is0 = new ClassPathResource(imagePath).getInputStream();
}
List<PstnAndSize> transformedMosaicInfos = mediaBean.getTransformedMosaic( List<PstnAndSize> transformedMosaicInfos = mediaBean.getTransformedMosaic(
imageKey, imagePath, new PstnAndSize(pstn[0],pstn[1], size[0], size[1]) imageKey, is0, new PstnAndSize(pstn[0],pstn[1], size[0], size[1])
); );
for(int k=0; k < transformedMosaicInfos.size(); k++) { for(int k=0; k < transformedMosaicInfos.size(); k++) {
PstnAndSize mosaicInfo = transformedMosaicInfos.get(k); PstnAndSize mosaicInfo = transformedMosaicInfos.get(k);
pdfPrintUtil.insertImage(doc, contentStream, blackImage, InputStream blackImageStream = new ClassPathResource("samplefiles/black.png").getInputStream();
pdfPrintUtil.insertImage(doc, contentStream, blackImageStream,
mosaicInfo.getPstn().to2Float(), mosaicInfo.getSize().to2Float()); mosaicInfo.getPstn().to2Float(), mosaicInfo.getSize().to2Float());
} }
} }
} else if(prototypeStng.getComponentType().equals("images")) { } else if(prototypeStng.getComponentType().equals("images")) {
List<String> imagePaths = pdfFormat.getMappingValues(otptArtclNm,defaultValue,forPost,dataObject,printOption,pdfPrintUtil); List<String> imagePaths = pdfFormat.getMappingValues(otptArtclNm,defaultValue,forPost,dataObject,printOption,pdfPrintUtil);
@ -513,22 +537,43 @@ public class IntegrationSearchServiceBean extends AbstractServiceBean implements
for (int i=0; i< devideInfos.size(); i++){ for (int i=0; i< devideInfos.size(); i++){
PstnAndSize devideInfo = devideInfos.get(i); PstnAndSize devideInfo = devideInfos.get(i);
String imagePath = imagePaths.get(i);
pdfPrintUtil.insertImage(doc, contentStream, if(ifEmpty(imagePath, ()-> "").equals("")) {
imagePaths.get(i), devideInfo.getPstn().to2Float(), devideInfo.getSize().to2Float()); continue;
}
InputStream is = null;
if(imagePaths.get(i).startsWith("files")) {
File imageFile = new File(imagePath);
is = new FileInputStream(imageFile);
} else {
is = new ClassPathResource(imagePath).getInputStream();
}
pdfPrintUtil.insertImage(doc, contentStream, is,
devideInfo.getPstn().to2Float(), devideInfo.getSize().to2Float());
if(otptArtclNm.equals("crdnPhoto") && !imageKeys.isEmpty()) { if(otptArtclNm.equals("crdnPhoto") && !imageKeys.isEmpty()) {
String blackImage = "samplefiles/black.png";
InputStream is0 = null;
String imagePath0 = imagePaths.get(i);
if(imagePath0.startsWith("files")) {
File imageFile0 = new File(imagePath0);
is0 = new FileInputStream(imageFile0);
} else {
is0 = new ClassPathResource(imagePath0).getInputStream();
}
List<PstnAndSize> transformedMosaicInfos = mediaBean.getTransformedMosaic( List<PstnAndSize> transformedMosaicInfos = mediaBean.getTransformedMosaic(
imageKeys.get(i), imagePaths.get(i), devideInfo imageKeys.get(i), is0, devideInfo
); );
for(int k=0; k < transformedMosaicInfos.size(); k++) { for(int k=0; k < transformedMosaicInfos.size(); k++) {
PstnAndSize mosaicInfo = transformedMosaicInfos.get(k); PstnAndSize mosaicInfo = transformedMosaicInfos.get(k);
InputStream blackImageStream = new ClassPathResource("samplefiles/black.png").getInputStream();
pdfPrintUtil.insertImage(doc, contentStream, blackImage, pdfPrintUtil.insertImage(doc, contentStream, blackImageStream,
mosaicInfo.getPstn().to2Float(), mosaicInfo.getSize().to2Float()); mosaicInfo.getPstn().to2Float(), mosaicInfo.getSize().to2Float());
} }
@ -540,7 +585,7 @@ public class IntegrationSearchServiceBean extends AbstractServiceBean implements
} }
} }//출력항목 loop 끝
if(!completeFoldLine) { if(!completeFoldLine) {
if(!otptBscStng.string("FOLD_LINE_PSTN_SE_CD").equals("")) { if(!otptBscStng.string("FOLD_LINE_PSTN_SE_CD").equals("")) {
@ -549,7 +594,8 @@ public class IntegrationSearchServiceBean extends AbstractServiceBean implements
} }
contentStream.close(); contentStream.close();
}
} //출력자료건수 loop 끝
doc.save(resultFilePath); doc.save(resultFilePath);
@ -619,12 +665,22 @@ public class IntegrationSearchServiceBean extends AbstractServiceBean implements
for(int j=0; j < fileInfoList.size(); j++){ for(int j=0; j < fileInfoList.size(); j++){
DataObject fileInfo = fileInfoList.get(j); DataObject fileInfo = fileInfoList.get(j);
List<DataObject> mosaicInfos = mediaBean.getMosaicList(fileInfo.string("FILE_ID")); List<DataObject> mosaicInfos = mediaBean.getMosaicList(fileInfo.string("FILE_ID"));
String orgnFilePath = fileInfo.string("FILE_PATH");
if(ifEmpty(orgnFilePath, ()->"").equals("")) {
continue;
}
File orgnFile = new File(fileInfo.string("FILE_PATH")); InputStream orgnFileInputStream = null;
if(orgnFilePath.startsWith("files")) {
File orgnFile = new File(orgnFilePath);
if(!orgnFile.exists() || !orgnFile.canRead()) { if(!orgnFile.exists() || !orgnFile.canRead()) {
continue; continue;
} }
orgnFileInputStream = new FileInputStream(orgnFile);
} else {
orgnFileInputStream = new ClassPathResource(orgnFilePath).getInputStream();
}
String modifiedFileName = "P"+fileInfo.string("INF_KEY")+CmmnUtil.indexToAlphabet(j, true)+"."+"JPG"; String modifiedFileName = "P"+fileInfo.string("INF_KEY")+CmmnUtil.indexToAlphabet(j, true)+"."+"JPG";
@ -633,9 +689,9 @@ public class IntegrationSearchServiceBean extends AbstractServiceBean implements
File modifiedFile = new File(modifiedFilePath); File modifiedFile = new File(modifiedFilePath);
if(mosaicInfos != null) { if(mosaicInfos != null) {
CmmnUtil.createMaskedImage(orgnFile, modifiedFile, mosaicInfos); CmmnUtil.createMaskedImage(orgnFileInputStream, modifiedFile, mosaicInfos);
} else { } else {
Files.copy(orgnFile.toPath(), modifiedFile.toPath(), StandardCopyOption.REPLACE_EXISTING); Files.copy(orgnFileInputStream, modifiedFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
} }
dataObject.set("CRDN_PHOTO"+(j+1), modifiedFilePath); dataObject.set("CRDN_PHOTO"+(j+1), modifiedFilePath);
} }

@ -1,7 +1,7 @@
package cokr.xit.fims.sprt.service.bean; package cokr.xit.fims.sprt.service.bean;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.File; import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -77,17 +77,12 @@ public class MediaBean extends AbstractComponent {
return mediaMapper.selectMosaicList(fileId); return mediaMapper.selectMosaicList(fileId);
} }
public List<PstnAndSize> getTransformedMosaic(String imageKey, String imagePath, PstnAndSize pstnAndSize_in_print) { public List<PstnAndSize> getTransformedMosaic(String imageKey, InputStream inputStream, PstnAndSize pstnAndSize_in_print) {
List<PstnAndSize> result = new ArrayList<>(); List<PstnAndSize> result = new ArrayList<>();
try { try {
File imageFile = new File(imagePath);
if(!imageFile.exists() || !imageFile.canRead()) {
result.add(new PstnAndSize(0, 0, 0, 0));
return result;
}
BufferedImage image = ImageIO.read(imageFile); BufferedImage image = ImageIO.read(inputStream);
float originalWidth = image.getWidth(null); float originalWidth = image.getWidth(null);
float originalHeight = image.getHeight(null); float originalHeight = image.getHeight(null);
float transX = pstnAndSize_in_print.getWidth() / originalWidth; float transX = pstnAndSize_in_print.getWidth() / originalWidth;

Before

Width:  |  Height:  |  Size: 137 B

After

Width:  |  Height:  |  Size: 137 B

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Loading…
Cancel
Save