From 05c2559af5d884c3fea2f15f20f6c856110dae5b Mon Sep 17 00:00:00 2001 From: Usama Khan Date: Fri, 28 Feb 2025 00:07:36 -0800 Subject: [PATCH] fixed sized and Printer Configuration --- .../model/ctp/BarcodeStickerSize.java | 2 +- .../service/BarcodeService.java | 48 ++++--------------- 2 files changed, 10 insertions(+), 40 deletions(-) diff --git a/src/main/java/com/utopiaindustries/model/ctp/BarcodeStickerSize.java b/src/main/java/com/utopiaindustries/model/ctp/BarcodeStickerSize.java index 3bd16bb..f8e3381 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, 125.73f ,10 , 10, 20, 6, 60, 60, 125, 125, 4, 9, 7); + SIZE_1_X_2( 67.69f, 128.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 46bb8d0..b69a4ea 100644 --- a/src/main/java/com/utopiaindustries/service/BarcodeService.java +++ b/src/main/java/com/utopiaindustries/service/BarcodeService.java @@ -287,7 +287,6 @@ public class BarcodeService { g2d.drawString(text, adjustedX, adjustedY); } - public void getBarcodeImagesForStitchItems(List artifacts, BarcodeStickerSize stickerSize) throws Exception { @@ -313,7 +312,7 @@ public class BarcodeService { float qrY =stickerSize.getMarginLeft()+50 ; float qrX = stickerSize.getMarginTop(); - qrCodeImage.setFixedPosition(qrX - 16, qrY-47); + qrCodeImage.setFixedPosition(qrX - 16, qrY-40); document.add(qrCodeImage); float textX = stickerSize.getMarginLeft() + 40; @@ -326,7 +325,7 @@ public class BarcodeService { int maxLength = 14; List lines = new ArrayList<>(); - for (int i = 0; i < 3; i++) { + 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+", ""); @@ -336,7 +335,7 @@ public class BarcodeService { float labelWidth = 67.69f; float textBoxWidth = 220; - float textY1 = textY-30; + float textY1 = textY-23; float textXCenter = textX + (labelWidth / 2) - (textBoxWidth / 2)-50; for (String line : lines) { @@ -354,13 +353,13 @@ public class BarcodeService { String id = String.valueOf(artifact.getId()); document.add(new Paragraph(id) .setFont(font) - .setFontColor(ColorConstants.BLACK) .setBold() + .setFontColor(ColorConstants.BLACK) .setFontSize(stickerSize.getTextSize() + 8) .setTextAlignment(TextAlignment.LEFT) - .setFixedPosition(textX - 25, textY + 8, 140)); + .setFixedPosition(textX - 25, textY + 13, 100)); - float dottedLine = textY - 60; + float dottedLine = textY - 65; for(int i= 0 ;i<16;i++){ document.add(new Paragraph("|") .setFontSize(stickerSize.getTextSize()) @@ -368,12 +367,12 @@ public class BarcodeService { .setBold() .setRotationAngle(-Math.PI / 2) .setTextAlignment(TextAlignment.LEFT) - .setFixedPosition(dottedLine,textX+40, 100)); + .setFixedPosition(dottedLine,textX+45, 100)); dottedLine += 7; } - float dottedLine2 = textY - 60; + float dottedLine2 = textY - 65; for(int i= 0 ;i<16;i++){ document.add(new Paragraph("|") .setFontSize(stickerSize.getTextSize()) @@ -381,7 +380,7 @@ public class BarcodeService { .setBold() .setRotationAngle(-Math.PI / 2) .setTextAlignment(TextAlignment.LEFT) - .setFixedPosition(dottedLine2,textX+75, 100)); + .setFixedPosition(dottedLine2,textX+80, 100)); dottedLine2 += 7; } @@ -434,38 +433,9 @@ public class BarcodeService { public void printLabel(BufferedImage bufferedImage) throws Exception { Connection connection = new TcpConnection(ipAddress, port); connection.open(); - ZebraPrinter printer = ZebraPrinterFactory.getInstance(connection); - - //Reset Printer Settings - String resetSettings = "^XA^JUS^XZ"; - printer.sendCommand(resetSettings); - - //Force Label Length & Disable Auto Feed - String lengthFix = "^XA^LL555^PON^XZ"; // **Reduce Length (880) & Disable Auto Feed - printer.sendCommand(lengthFix); - - //Apply New Settings - String settings = "^XA" + - "^MMT" + // Continuous Mode - "^MTT" + // Thermal Transfer Mode - "^LH0,0" + // Home Position - "^PR6" + // Print Speed (~120mm/sec) - "^MD25" + // Darkness Level - "^PW541" + // Label Width (67.69mm for 203 DPI) - "^LL550" + // Reduced Label Length (fix gap) - "^PN0" + // No Extra Page Feed - "^PON" + // Disable Printer's Auto Feed Mode - "^XZ"; - - printer.sendCommand(settings); - - // Convert BufferedImage to ZebraImage ZebraImage zebraImage = new ZebraImage(bufferedImage); - - // Print image printer.printImage(zebraImage, 0, 0, 0, 0, false); - connection.close(); } } \ No newline at end of file