From b90079232525365cbbd62861210c166ed8cad6ec Mon Sep 17 00:00:00 2001 From: leebeomjun Date: Tue, 28 Nov 2023 16:24:09 +0900 Subject: [PATCH] =?UTF-8?q?pdf=EC=B6=9C=EB=A0=A5=20=EC=88=98=EC=A0=95(?= =?UTF-8?q?=ED=85=8D=EC=8A=A4=ED=8A=B8=20=EC=A0=95=EB=A0=AC=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xit/fims/cmmn/pdf/DefaultOtptStng.java | 7 ++++ .../cokr/xit/fims/cmmn/pdf/PDFPrintUtil.java | 32 ++++++++++++++++--- .../xit/fims/cmmn/pdf/format/Advntce.java | 15 +++++---- .../sprt/service/bean/Sprt01ServiceBean.java | 8 ++--- 4 files changed, 48 insertions(+), 14 deletions(-) diff --git a/src/main/java/cokr/xit/fims/cmmn/pdf/DefaultOtptStng.java b/src/main/java/cokr/xit/fims/cmmn/pdf/DefaultOtptStng.java index 1b4520be..ec12bdb8 100644 --- a/src/main/java/cokr/xit/fims/cmmn/pdf/DefaultOtptStng.java +++ b/src/main/java/cokr/xit/fims/cmmn/pdf/DefaultOtptStng.java @@ -20,6 +20,7 @@ public class DefaultOtptStng { this.fontColor="BLACK"; this.fontStyle="FILL"; + this.align = "left"; this.forPost = false; this.unique = false; } @@ -40,6 +41,11 @@ public class DefaultOtptStng { return this; } + public DefaultOtptStng align(String type) { + this.align = type; + return this; + } + public DefaultOtptStng size(float width, float height) { this.widthSz = width; this.heightSz = height; @@ -87,6 +93,7 @@ public class DefaultOtptStng { private boolean forPost; private float widthSz; private float heightSz; + private String align; private String fontNm; private int fontSize; private String fontColor; diff --git a/src/main/java/cokr/xit/fims/cmmn/pdf/PDFPrintUtil.java b/src/main/java/cokr/xit/fims/cmmn/pdf/PDFPrintUtil.java index 88f60cc3..3e618fbf 100644 --- a/src/main/java/cokr/xit/fims/cmmn/pdf/PDFPrintUtil.java +++ b/src/main/java/cokr/xit/fims/cmmn/pdf/PDFPrintUtil.java @@ -65,12 +65,21 @@ public class PDFPrintUtil extends PrintUtil { } // - public void writeText(PDPageContentStream contentStream, String text, float[] XYmm, + public void writeText(PDPageContentStream contentStream, String text, + float[] XYmm, float textAreaWidth_mm, String align, PDType0Font font, int fontSize, RenderingMode fontStyle, PDColor fontColor) { try { - + if(text == null) { + text = ""; + } float[] xyAbsolute = this.toPDFCoordinate(XYmm).absolute(); + float textAreaWidth_pt = mmToPt(textAreaWidth_mm); + float textWidth = (font.getStringWidth(text) / 1000.0f) * fontSize; + + float textAreaHalfWidth_pt = textAreaWidth_pt / 2; + float textHalfWidth = textWidth / 2; + contentStream.beginText(); contentStream.setFont(font, fontSize); @@ -78,9 +87,16 @@ public class PDFPrintUtil extends PrintUtil { contentStream.setNonStrokingColor(fontColor); - contentStream.newLineAtOffset(xyAbsolute[0], xyAbsolute[1]); + if(align.equals("right")) { + contentStream.newLineAtOffset(xyAbsolute[0] - textWidth + textAreaWidth_pt, xyAbsolute[1]); + } else if(align.equals("center")){ + contentStream.newLineAtOffset(xyAbsolute[0] - textHalfWidth + textAreaHalfWidth_pt, xyAbsolute[1]); + } else { + contentStream.newLineAtOffset(xyAbsolute[0], xyAbsolute[1]); + } contentStream.showText(text); + contentStream.endText(); } catch (IOException e) { @@ -176,7 +192,7 @@ public class PDFPrintUtil extends PrintUtil { } public float[] getSize(DefaultOtptStng defaultStng, DataObject sggStng) { - if(!sggStng.string("WIDTH_SZ").equals("") && !sggStng.string("HEIGHT_SZ").equals("")) { + if(!sggStng.string("WIDTH_SZ").equals("")) { return new float[] { sggStng.number("WIDTH_SZ").floatValue(), sggStng.number("HEIGHT_SZ").floatValue() @@ -188,4 +204,12 @@ public class PDFPrintUtil extends PrintUtil { }; } } + + public String getAlign(DefaultOtptStng defaultStng, DataObject sggStng) { + if(!sggStng.string("TEXT_SORT").equals("")) { + return sggStng.string("TEXT_SORT"); + } else { + return defaultStng.getAlign(); + } + } } diff --git a/src/main/java/cokr/xit/fims/cmmn/pdf/format/Advntce.java b/src/main/java/cokr/xit/fims/cmmn/pdf/format/Advntce.java index 2d71312e..ae4a1418 100644 --- a/src/main/java/cokr/xit/fims/cmmn/pdf/format/Advntce.java +++ b/src/main/java/cokr/xit/fims/cmmn/pdf/format/Advntce.java @@ -15,11 +15,6 @@ public class Advntce extends PDFFormat { public Advntce(){ addForPost( - text("postReceiverAddr","").post().a4(0, 0).letter(0, 0), - text("postReceiverDtlAddr","").post().a4(0, 0).letter(0, 0), - text("postReceiverZip","").a4(0, 0).letter(0, 0), - text("postReceiver","").a4(0, 0).letter(0, 0), - image("postSenderLogo","").a4(10, 0).letter(0, 0).size(0, 0), text("postSenderInst","").a4(10, 10).letter(0, 0), text("postSenderDept","").a4(50, 10).letter(0, 0), @@ -27,12 +22,20 @@ public class Advntce extends PDFFormat { text("postSenderDtlAddr","").a4(10, 30).letter(0, 0), text("postSenderZip","").a4(10, 40).letter(0, 0), text("postSenderTel","").a4(10, 50).letter(0, 0), - text("postSenderFax","").a4(50, 50).letter(0, 0) + text("postSenderFax","").a4(50, 50).letter(0, 0), + + text("postReceiverAddr","").a4(100, 50).letter(0, 0).size(90, 0).align("right"), + text("postReceiverDtlAddr","").a4(100, 60).letter(0, 0).size(90, 0).align("right"), + text("postReceiver","").a4(100, 70).letter(0, 0).size(90, 0).align("right"), + text("postReceiverZip","").a4(100, 80).letter(0, 0).size(90, 0).align("right") ); add( image("background","").a4(0, 0).letter(0, 0).size(0, 0), image("photo1","").a4(0, 0).letter(0, 0).size(0, 0), + image("photo2","").a4(0, 0).letter(0, 0).size(0, 0), + image("photo3","").a4(0, 0).letter(0, 0).size(0, 0), + image("photo4","").a4(0, 0).letter(0, 0).size(0, 0), text("rtpyrNm",""), text("rtpyrNo",""), diff --git a/src/main/java/cokr/xit/fims/sprt/service/bean/Sprt01ServiceBean.java b/src/main/java/cokr/xit/fims/sprt/service/bean/Sprt01ServiceBean.java index c7c8fedd..9fd36d4d 100644 --- a/src/main/java/cokr/xit/fims/sprt/service/bean/Sprt01ServiceBean.java +++ b/src/main/java/cokr/xit/fims/sprt/service/bean/Sprt01ServiceBean.java @@ -372,11 +372,13 @@ public class Sprt01ServiceBean extends AbstractServiceBean implements Sprt01Serv .filter(item -> item.getOtptNm().equals(otptNm)).toList().get(0); float[] pstn = pdfPrintUtil.getPstnStng(predefined, otptItemStng, otptPaperSeCd); + float[] size = pdfPrintUtil.getSize(predefined, otptItemStng); + boolean forPost = predefined.isForPost(); String defaultValue = predefined.getOtptBscVl(); if(predefined.getContentType().equals("text")) { - + String align = pdfPrintUtil.getAlign(predefined, otptItemStng); PDType0Font font = pdfPrintUtil.getFontType(predefined, otptItemStng, fontMap); int fontSz = pdfPrintUtil.getFontSize(predefined, otptItemStng); RenderingMode fontStyle = pdfPrintUtil.getFontStyle(predefined, otptItemStng); @@ -384,12 +386,10 @@ public class Sprt01ServiceBean extends AbstractServiceBean implements Sprt01Serv String textValue = pdfFormat.getMappingValue(otptNm,defaultValue,forPost,dataObject,printOption,pdfPrintUtil); - pdfPrintUtil.writeText(contentStream, textValue, pstn, font, fontSz, fontStyle, fontColor); + pdfPrintUtil.writeText(contentStream, textValue, pstn, size[0], align, font, fontSz, fontStyle, fontColor); } else if(predefined.getContentType().equals("image")) { - float[] size = pdfPrintUtil.getSize(predefined, otptItemStng); - String imagePath = pdfFormat.getMappingValue(otptNm,defaultValue,forPost,dataObject,printOption,pdfPrintUtil); pdfPrintUtil.insertImage(doc, contentStream, imagePath, pstn, size);