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 86899e59..ea32e32f 100644 --- a/src/main/java/cokr/xit/fims/cmmn/pdf/PDFPrintUtil.java +++ b/src/main/java/cokr/xit/fims/cmmn/pdf/PDFPrintUtil.java @@ -25,9 +25,9 @@ public class PDFPrintUtil extends PrintUtil { public void setting(String paperType) { if(paperType.equals("01")) { - this.paperMilimeter = new float[] {210 , 297}; + this.paperMilimeter = new float[] {210.0f , 297.0f}; } else if(paperType.equals("02")){ - this.paperMilimeter = new float[] {216 , 279}; + this.paperMilimeter = new float[] {216.0f , 279.0f}; } } @@ -54,7 +54,9 @@ public class PDFPrintUtil extends PrintUtil { } - // + /** + * mm단위로 입력된 값을 pdf좌표계 형식으로 변환한다. + */ public PDFCoordinate toPDFCoordinate(float[] XYmm) { float Xmm = XYmm[0]; float Ymm = XYmm[1]; @@ -67,7 +69,9 @@ public class PDFPrintUtil extends PrintUtil { return new PDFCoordinate(Xpt, Ypt, YptMax); } - // + /** + * 텍스트를 pdf에 입력한다. + */ public void writeText(PDPageContentStream contentStream, String allText, float[] XYmm, float textAreaWidth_mm, String align, String newLineYn, PDType0Font font, int fontSize, RenderingMode fontStyle, PDColor fontColor) { @@ -112,7 +116,7 @@ public class PDFPrintUtil extends PrintUtil { if(align.equals("right")) { firstLineAlignCorrection = textAreaWidth_pt - firstLineWidth; } else if(align.equals("center")) { - firstLineAlignCorrection = (textAreaWidth_pt - firstLineWidth)/2; + firstLineAlignCorrection = (textAreaWidth_pt - firstLineWidth)/2.0f; } float resultX = xyAbsolute[0] + firstLineAlignCorrection; @@ -121,6 +125,7 @@ public class PDFPrintUtil extends PrintUtil { contentStream.showText(textArr[0]); if(textArr.length > 1) { + float beforeLineWidth = firstLineWidth; for(int i = 1; i < textArr.length; i++) { String thisLine = textArr[i]; @@ -128,13 +133,15 @@ public class PDFPrintUtil extends PrintUtil { float alignCorrection = 0; if(align.equals("right")) { - alignCorrection = firstLineWidth - thisLineWidth; + alignCorrection = beforeLineWidth - thisLineWidth; } if(align.equals("center")) { - alignCorrection = (firstLineWidth - thisLineWidth)/2; + alignCorrection = (beforeLineWidth - thisLineWidth)/2.0f; } contentStream.newLineAtOffset(alignCorrection, -(fontSize + 1)); contentStream.showText(thisLine); + + beforeLineWidth = thisLineWidth; } @@ -148,7 +155,9 @@ public class PDFPrintUtil extends PrintUtil { } - + /** + * 글꼴모양,폰트크기 등에 따른 텍스트의 가로 길이(pt)를 계산한다. + */ public float calcTextWidth(PDType0Font font, int fontSize, String text) { try { return (font.getStringWidth(text) / 1000.0f) * fontSize; @@ -157,6 +166,9 @@ public class PDFPrintUtil extends PrintUtil { } } + /** + * 출력할 텍스트가 지정한 영역 안에 들어가지 않을 경우 줄바꿈 처리를 위해 텍스트를 나누어 배열로 반환한다. + */ public String[] splitByLineForLargeText(PDType0Font font, int fontSize, String allText, float textAreaWidth_pt) { float allTextWidth = calcTextWidth(font, fontSize, allText); @@ -179,6 +191,9 @@ public class PDFPrintUtil extends PrintUtil { return textList.toArray(new String[textList.size()]); } + /** + * 텍스트를 줄바꿈 처리할 경우 첫 라인에 출력될 글자 수를 반환한다. + */ private int getLengthForLine(PDType0Font font, int fontSize, String allText, float textAreaWidth_pt) { int forLine = allText.length(); if(forLine <= 1) { @@ -199,6 +214,9 @@ public class PDFPrintUtil extends PrintUtil { return forLine; } + /** + * pdf에 이미지를 삽입한다. + */ public void insertImage(PDDocument doc, PDPageContentStream contentStream, String imagePath, float[] XYmm, float[] SIZEmm) {