fix qr code margining issue
parent
6ac6a42a60
commit
b1b4c6b634
|
@ -7,7 +7,7 @@ public enum BarcodeStickerSize {
|
||||||
SIZE_4_X_4( 4 * 72, 4 * 72, 8, 8, 8, 8, 200, 100, 250, 250, 14, 9, 7),
|
SIZE_4_X_4( 4 * 72, 4 * 72, 8, 8, 8, 8, 200, 100, 250, 250, 14, 9, 7),
|
||||||
SIZE_1_75_X_3_5( 3.5f * 72, 1.75f * 72, 10, 10, 6, 6, 50, 50, 125, 125, 14, 9, 7),
|
SIZE_1_75_X_3_5( 3.5f * 72, 1.75f * 72, 10, 10, 6, 6, 50, 50, 125, 125, 14, 9, 7),
|
||||||
SIZE_4_X_7( 7f * 72, 4f * 72, 200, 10, 40, 6, 50, 40, 125, 125, 14, 9, 7),
|
SIZE_4_X_7( 7f * 72, 4f * 72, 200, 10, 40, 6, 50, 40, 125, 125, 14, 9, 7),
|
||||||
SIZE_1_X_2( 67.69f, 128.73f ,10 , 10, 20, 6, 60, 60, 125, 125, 4, 9, 7);
|
SIZE_1_X_2( 67.69f, 139.73f ,10 , 10, 20, 6, 60, 60, 125, 125, 4, 9, 7);
|
||||||
|
|
||||||
private final float width;
|
private final float width;
|
||||||
private final float height;
|
private final float height;
|
||||||
|
|
|
@ -312,7 +312,7 @@ public class BarcodeService {
|
||||||
float qrY =stickerSize.getMarginLeft()+50 ;
|
float qrY =stickerSize.getMarginLeft()+50 ;
|
||||||
float qrX = stickerSize.getMarginTop();
|
float qrX = stickerSize.getMarginTop();
|
||||||
|
|
||||||
qrCodeImage.setFixedPosition(qrX - 16, qrY-40);
|
qrCodeImage.setFixedPosition(qrX - 16, qrY-35);
|
||||||
document.add(qrCodeImage);
|
document.add(qrCodeImage);
|
||||||
|
|
||||||
float textX = stickerSize.getMarginLeft() + 40;
|
float textX = stickerSize.getMarginLeft() + 40;
|
||||||
|
@ -323,35 +323,50 @@ public class BarcodeService {
|
||||||
String combinedText = sku + " \\ " + jobCardCode + " \\ " + artifact.getBundleId();
|
String combinedText = sku + " \\ " + jobCardCode + " \\ " + artifact.getBundleId();
|
||||||
combinedText = combinedText.replaceAll("\\s+", "");
|
combinedText = combinedText.replaceAll("\\s+", "");
|
||||||
|
|
||||||
int maxLength = 14;
|
int maxLength = 12;
|
||||||
|
int start = 0;
|
||||||
|
int lineCount = 0;
|
||||||
List<String> lines = new ArrayList<>();
|
List<String> lines = new ArrayList<>();
|
||||||
for (int i = 0; i < 5; i++) {
|
|
||||||
int start = i * maxLength;
|
while (start < combinedText.length() && lineCount < 5) {
|
||||||
if (start < combinedText.length()) {
|
int end = Math.min(start + maxLength, combinedText.length());
|
||||||
String part = combinedText.substring(start, Math.min(start + maxLength, combinedText.length())).replaceAll("\\s+", "");
|
String part = combinedText.substring(start, end);
|
||||||
lines.add(part);
|
|
||||||
|
if (part.matches(".*[^a-zA-Z0-9 ].*")) {
|
||||||
|
if(combinedText.length() - start<=17 && combinedText.length() - start>0){
|
||||||
|
end = Math.min(start + maxLength + 5, combinedText.length());
|
||||||
|
part = combinedText.substring(start, end);
|
||||||
|
}else {
|
||||||
|
end = Math.min(start + maxLength + 3, combinedText.length());
|
||||||
|
part = combinedText.substring(start, end);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
part = part.replaceAll("\\s+", "");
|
||||||
|
lines.add(part);
|
||||||
|
start = end;
|
||||||
|
lineCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
float labelWidth = 67.69f;
|
float labelWidth = 67.69f;
|
||||||
float textBoxWidth = 220;
|
float textBoxWidth = 120f;
|
||||||
float textY1 = textY-23;
|
float textY1 = textY-23;
|
||||||
float textXCenter = textX + (labelWidth / 2) - (textBoxWidth / 2)-50;
|
float textXCenter = textX + (labelWidth / 2) - (textBoxWidth / 2)-50;
|
||||||
|
|
||||||
for (String line : lines) {
|
for (String line : lines) {
|
||||||
Paragraph rotatedText = new Paragraph(line)
|
Paragraph rotatedText = new Paragraph(line)
|
||||||
.setFontColor(ColorConstants.BLACK)
|
.setFontColor(ColorConstants.BLACK)
|
||||||
.setFontSize(stickerSize.getTextSize() + 2)
|
.setFontSize(stickerSize.getTextSize()+2)
|
||||||
.setTextAlignment(TextAlignment.CENTER)
|
.setTextAlignment(TextAlignment.CENTER)
|
||||||
.setFixedPosition(textXCenter, textY1-18, textBoxWidth);
|
.setFixedPosition(textXCenter, textY1-13, textBoxWidth);
|
||||||
|
|
||||||
document.add(rotatedText);
|
document.add(rotatedText);
|
||||||
textY1 -= 6;
|
textY1 -= 6;
|
||||||
}
|
}
|
||||||
|
|
||||||
PdfFont font = PdfFontFactory.createFont(StandardFonts.COURIER_OBLIQUE);
|
PdfFont font = PdfFontFactory.createFont(StandardFonts.COURIER);
|
||||||
String id = String.valueOf(artifact.getId());
|
String id = String.valueOf(artifact.getId());
|
||||||
float textSize = stickerSize.getTextSize() + 8;
|
float textSize = stickerSize.getTextSize() + 6;
|
||||||
float charWidth = textSize * 0.6f;
|
float charWidth = textSize * 0.6f;
|
||||||
float idWidth = id.length() * charWidth;
|
float idWidth = id.length() * charWidth;
|
||||||
float xCentered = (labelWidth / 2f) - (idWidth / 2f);
|
float xCentered = (labelWidth / 2f) - (idWidth / 2f);
|
||||||
|
@ -361,7 +376,7 @@ public class BarcodeService {
|
||||||
.setBold()
|
.setBold()
|
||||||
.setFontColor(ColorConstants.BLACK)
|
.setFontColor(ColorConstants.BLACK)
|
||||||
.setFontSize(textSize)
|
.setFontSize(textSize)
|
||||||
.setFixedPosition(xCentered, textY + 13, 100));
|
.setFixedPosition(xCentered, textY + 18, 100));
|
||||||
|
|
||||||
|
|
||||||
float dottedLine = textY - 65;
|
float dottedLine = textY - 65;
|
||||||
|
@ -372,7 +387,7 @@ public class BarcodeService {
|
||||||
.setBold()
|
.setBold()
|
||||||
.setRotationAngle(-Math.PI / 2)
|
.setRotationAngle(-Math.PI / 2)
|
||||||
.setTextAlignment(TextAlignment.LEFT)
|
.setTextAlignment(TextAlignment.LEFT)
|
||||||
.setFixedPosition(dottedLine,textX+45, 100));
|
.setFixedPosition(dottedLine,textX+55, 100));
|
||||||
|
|
||||||
dottedLine += 7;
|
dottedLine += 7;
|
||||||
}
|
}
|
||||||
|
@ -385,7 +400,7 @@ public class BarcodeService {
|
||||||
.setBold()
|
.setBold()
|
||||||
.setRotationAngle(-Math.PI / 2)
|
.setRotationAngle(-Math.PI / 2)
|
||||||
.setTextAlignment(TextAlignment.LEFT)
|
.setTextAlignment(TextAlignment.LEFT)
|
||||||
.setFixedPosition(dottedLine2,textX+80, 100));
|
.setFixedPosition(dottedLine2,textX+90, 100));
|
||||||
|
|
||||||
dottedLine2 += 7;
|
dottedLine2 += 7;
|
||||||
}
|
}
|
||||||
|
@ -394,11 +409,13 @@ public class BarcodeService {
|
||||||
document.add(new AreaBreak());
|
document.add(new AreaBreak());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pdfDoc.getNumberOfPages() > artifacts.size()) {
|
if (pdfDoc.getNumberOfPages() > artifacts.size()) {
|
||||||
pdfDoc.removePage(pdfDoc.getNumberOfPages());
|
pdfDoc.removePage(pdfDoc.getNumberOfPages());
|
||||||
}
|
}
|
||||||
|
|
||||||
document.close();
|
document.close();
|
||||||
sendPdfToZebraPrinter(pdfPath.toFile());
|
// sendPdfToZebraPrinter(pdfPath.toFile());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendPdfToZebraPrinter(File pdfFile) throws Exception {
|
public void sendPdfToZebraPrinter(File pdfFile) throws Exception {
|
||||||
|
|
Loading…
Reference in New Issue