diff --git a/src/main/java/com/utopiaindustries/model/ctp/BarcodeStickerSize.java b/src/main/java/com/utopiaindustries/model/ctp/BarcodeStickerSize.java index f8e3381..1c79366 100644 --- a/src/main/java/com/utopiaindustries/model/ctp/BarcodeStickerSize.java +++ b/src/main/java/com/utopiaindustries/model/ctp/BarcodeStickerSize.java @@ -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_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_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 height; diff --git a/src/main/java/com/utopiaindustries/service/BarcodeService.java b/src/main/java/com/utopiaindustries/service/BarcodeService.java index f4c01e1..76a867e 100644 --- a/src/main/java/com/utopiaindustries/service/BarcodeService.java +++ b/src/main/java/com/utopiaindustries/service/BarcodeService.java @@ -312,7 +312,7 @@ public class BarcodeService { float qrY =stickerSize.getMarginLeft()+50 ; float qrX = stickerSize.getMarginTop(); - qrCodeImage.setFixedPosition(qrX - 16, qrY-40); + qrCodeImage.setFixedPosition(qrX - 16, qrY-35); document.add(qrCodeImage); float textX = stickerSize.getMarginLeft() + 40; @@ -323,35 +323,50 @@ public class BarcodeService { String combinedText = sku + " \\ " + jobCardCode + " \\ " + artifact.getBundleId(); combinedText = combinedText.replaceAll("\\s+", ""); - int maxLength = 14; + int maxLength = 12; + int start = 0; + int lineCount = 0; List lines = new ArrayList<>(); - for (int i = 0; i < 5; i++) { - int start = i * maxLength; - if (start < combinedText.length()) { - String part = combinedText.substring(start, Math.min(start + maxLength, combinedText.length())).replaceAll("\\s+", ""); - lines.add(part); + + while (start < combinedText.length() && lineCount < 5) { + int end = Math.min(start + maxLength, combinedText.length()); + String part = combinedText.substring(start, end); + + 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 textBoxWidth = 220; + float textBoxWidth = 120f; float textY1 = textY-23; float textXCenter = textX + (labelWidth / 2) - (textBoxWidth / 2)-50; for (String line : lines) { Paragraph rotatedText = new Paragraph(line) .setFontColor(ColorConstants.BLACK) - .setFontSize(stickerSize.getTextSize() + 2) + .setFontSize(stickerSize.getTextSize()+2) .setTextAlignment(TextAlignment.CENTER) - .setFixedPosition(textXCenter, textY1-18, textBoxWidth); + .setFixedPosition(textXCenter, textY1-13, textBoxWidth); document.add(rotatedText); textY1 -= 6; } - PdfFont font = PdfFontFactory.createFont(StandardFonts.COURIER_OBLIQUE); + PdfFont font = PdfFontFactory.createFont(StandardFonts.COURIER); String id = String.valueOf(artifact.getId()); - float textSize = stickerSize.getTextSize() + 8; + float textSize = stickerSize.getTextSize() + 6; float charWidth = textSize * 0.6f; float idWidth = id.length() * charWidth; float xCentered = (labelWidth / 2f) - (idWidth / 2f); @@ -361,7 +376,7 @@ public class BarcodeService { .setBold() .setFontColor(ColorConstants.BLACK) .setFontSize(textSize) - .setFixedPosition(xCentered, textY + 13, 100)); + .setFixedPosition(xCentered, textY + 18, 100)); float dottedLine = textY - 65; @@ -372,7 +387,7 @@ public class BarcodeService { .setBold() .setRotationAngle(-Math.PI / 2) .setTextAlignment(TextAlignment.LEFT) - .setFixedPosition(dottedLine,textX+45, 100)); + .setFixedPosition(dottedLine,textX+55, 100)); dottedLine += 7; } @@ -385,7 +400,7 @@ public class BarcodeService { .setBold() .setRotationAngle(-Math.PI / 2) .setTextAlignment(TextAlignment.LEFT) - .setFixedPosition(dottedLine2,textX+80, 100)); + .setFixedPosition(dottedLine2,textX+90, 100)); dottedLine2 += 7; } @@ -394,11 +409,13 @@ public class BarcodeService { document.add(new AreaBreak()); } } + if (pdfDoc.getNumberOfPages() > artifacts.size()) { pdfDoc.removePage(pdfDoc.getNumberOfPages()); } + document.close(); - sendPdfToZebraPrinter(pdfPath.toFile()); +// sendPdfToZebraPrinter(pdfPath.toFile()); } public void sendPdfToZebraPrinter(File pdfFile) throws Exception {