pdf출력 수정(텍스트 정렬 기능)

main
이범준 12 months ago
parent 254195fe30
commit b900792325

@ -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;

@ -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);
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();
}
}
}

@ -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",""),

@ -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);

Loading…
Cancel
Save