fixed barcode printer issue and add notification cut button

barcode-print
usama.jameel 2025-01-10 18:12:57 +05:00
parent 29686c0dd0
commit 6749f6eca2
5 changed files with 39 additions and 30 deletions

View File

@ -158,7 +158,8 @@ public class CuttingController {
}
try {
barcodeService.generateBarcodes( Arrays.asList( ids ), artifactType );
return ResponseEntity.ok();
redirectAttributes.addFlashAttribute( "success", "Barcode generated successfully" );
return "redirect:/cutting/bundles";
}catch (Exception e){
redirectAttributes.addFlashAttribute( "error", e );
return "redirect:/cutting/bundles";
@ -174,7 +175,8 @@ public class CuttingController {
}
try {
barcodeService.generateBarcodes( Arrays.asList( ids ), artifactType );
return ResponseEntity.ok();
redirectAttributes.addFlashAttribute( "success", "Master barcode generated successfully" );
return "redirect:/cutting/master-bundles";
}catch (Exception e){
redirectAttributes.addFlashAttribute( "error", e );
return "redirect:/cutting/master-bundles";

View File

@ -138,7 +138,8 @@ public class StitchingController {
}
try {
barcodeService.generateBarcodes( Arrays.asList( ids ), artifactType );
return ResponseEntity.ok();
redirectAttributes.addFlashAttribute( "success", "Barcode generated successfully" );
return "redirect:/stitching/stitching-offline-items";
}catch (Exception e){
redirectAttributes.addFlashAttribute( "error", e );
return "redirect:/stitching/stitching-offline-items";

View File

@ -5,7 +5,7 @@ public enum BarcodeStickerSize {
SIZE_1_5_X_3( 3 * 72, 1.5f * 72, 10, 10, 6, 6, 50, 50, 125, 125, 14, 9, 7),
SIZE_2_X_3( 3 * 72, 2 * 72, 10, 10, 6, 6, 50, 50, 125, 125, 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( 7f * 72, 4f * 72, 10, 10, 6, 6, 50, 50, 125, 125, 14, 9, 7);
private final float width;

View File

@ -1,12 +1,6 @@
package com.utopiaindustries.service;
import com.google.zxing.BarcodeFormat;
import com.itextpdf.html2pdf.ConverterProperties;
import com.itextpdf.html2pdf.resolver.font.DefaultFontProvider;
import com.itextpdf.text.*;
import com.itextpdf.text.Image;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.pdf.*;
import com.utopiaindustries.dao.ctp.BundleDAO;
import com.utopiaindustries.dao.ctp.FinishedItemDAO;
import com.utopiaindustries.dao.ctp.MasterBundleDAO;
@ -19,12 +13,6 @@ import com.zebra.sdk.comm.TcpConnection;
import com.zebra.sdk.graphics.internal.ZebraImage;
import com.zebra.sdk.printer.ZebraPrinter;
import com.zebra.sdk.printer.ZebraPrinterFactory;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.core.io.InputStreamResource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import javax.imageio.ImageIO;
@ -32,7 +20,6 @@ import java.awt.*;
import java.awt.Font;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.List;
@ -78,8 +65,9 @@ public class BarcodeService {
for (InventoryArtifact artifact : artifacts) {
// Create a blank BufferedImage (an image with the size of the sticker)
BufferedImage stickerImage = new BufferedImage((int) stickerSize.getWidth(), (int) stickerSize.getHeight(), BufferedImage.TYPE_INT_ARGB);
BufferedImage stickerImage = new BufferedImage((int) stickerSize.getWidth()*2, (int) stickerSize.getHeight()*2, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = stickerImage.createGraphics();
g2d.scale(2,2);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
// Set background color (white for the sticker)
@ -87,7 +75,7 @@ public class BarcodeService {
g2d.fillRect(0, 0, (int) stickerSize.getWidth(), (int) stickerSize.getHeight());
// Set font for SKU and barcode
Font font = new Font("Helvetica", Font.BOLD, stickerSize.getTextSizeSmall());
Font font = new Font("Helvetica", Font.BOLD, stickerSize.getTextSize()+10);
g2d.setFont(font);
// Add SKU to the image
@ -96,15 +84,15 @@ public class BarcodeService {
int textWidth = fontMetrics.stringWidth(sku);
int x = (int) ((stickerSize.getWidth() - textWidth) / 2);
g2d.setColor(Color.BLACK);
g2d.drawString(sku, x, stickerSize.getMarginTop() + fontMetrics.getAscent());
g2d.drawString(sku, x, stickerSize.getMarginTop() + fontMetrics.getAscent()+20);
// Create the barcode image
byte[] imgBytes = BarcodeUtils.getBarcodeImageByteArray(artifact.getBarcode(), BarcodeFormat.CODE_128, stickerSize.getImageWidthBarcode(), stickerSize.getImageHeightBarcode());
byte[] imgBytes = BarcodeUtils.getBarcodeImageByteArray(artifact.getBarcode(), BarcodeFormat.CODE_128, stickerSize.getImageWidthBarcode()+500, stickerSize.getImageHeightBarcode()+30);
BufferedImage barcodeImage = ImageIO.read(new ByteArrayInputStream(imgBytes));
// Draw the barcode image on the sticker
int barcodeX =(int) (stickerSize.getWidth() - barcodeImage.getWidth()) / 2;
int barcodeY = stickerSize.getMarginTop() + fontMetrics.getAscent() + 10; // Add some margin
int barcodeY = stickerSize.getMarginTop() + fontMetrics.getAscent() + 30; // Add some margin
g2d.drawImage(barcodeImage, barcodeX, barcodeY, null);
// Add the barcode value below the barcode image
@ -115,24 +103,27 @@ public class BarcodeService {
if (artifactType.equalsIgnoreCase(Bundle.class.getSimpleName())) {
String typeText = String.format("%s : %d", artifact.getType(), artifact.getId());
g2d.drawString(typeText, (stickerSize.getWidth() - fontMetrics.stringWidth(typeText)) / 2,
barcodeY + barcodeImage.getHeight() + fontMetrics.getAscent() + 20);
barcodeY + barcodeImage.getHeight() + fontMetrics.getAscent() + 45);
g2d.setFont(new Font("Helvetica", Font.BOLD, stickerSize.getTextSize()+20));
g2d.drawString(String.valueOf(artifactType.toCharArray()[0]), (stickerSize.getWidth() - fontMetrics.stringWidth(String.valueOf(artifactType.toCharArray()[0]))) / 2,
barcodeY + barcodeImage.getHeight() + fontMetrics.getAscent() + 77);
} else {
// Add first character of artifact type
String type = String.valueOf(artifactType.charAt(0));
g2d.setFont(new Font("Helvetica", Font.BOLD, stickerSize.getTextSize()));
g2d.setFont(new Font("Helvetica", Font.BOLD, stickerSize.getTextSize()+10));
g2d.drawString(type, (stickerSize.getWidth() - fontMetrics.stringWidth(type)) / 2,
barcodeY + barcodeImage.getHeight() + fontMetrics.getAscent() + 40);
barcodeY + barcodeImage.getHeight() + fontMetrics.getAscent() + 45);
}
// Finalize drawing
g2d.dispose();
printLabel(stickerImage);
}
}
public void printLabel( BufferedImage bufferedImage ) throws Exception {
String ipAddr = "192.168.90.18";
String ipAddr = "192.168.90.160";
int port = 9100;
Connection connection = new TcpConnection( ipAddr, port );
connection.open();

View File

@ -6,14 +6,29 @@
<body>
<!-- flash messages -->
<div th:fragment="page-notices">
<div class="alert alert-danger" th:if="${error}" th:text="${error}"></div>
<div id="error" class="collapse show alert alert-danger" th:if="${error}" >
<div class="d-flex justify-content-between align-items-center" style="position: relative;">
<span th:text="${error}"></span>
<span class="btn font-lg" data-toggle="collapse" data-target="#error">&times;</span>
</div>
</div>
<div class="alert alert-danger" th:if="${errors != null && #lists.size(errors) > 0}">
<ul class="mb-0">
<li th:each="error: ${errors}" th:text="${error}"></li>
</ul>
</div>
<div class="alert alert-success" th:if="${success}" th:text="${success}"></div>
<div class="alert alert-warning" th:if="${warning}" th:text="${warning}"></div>
<div id="success" class="collapse show alert alert-success" th:if="${success}" >
<div class="d-flex justify-content-between align-items-center" style="position: relative;">
<span th:text="${success}"></span>
<span class="btn font-lg" data-toggle="collapse" data-target="#success">&times;</span>
</div>
</div>
<div id="warning" class="collapse show alert alert-warning" th:if="${warning}" th:text="${warning}">
<div class="d-flex justify-content-between align-items-center" style="position: relative;">
<span th:text="${warning}"></span>
<span class="btn font-lg" data-toggle="collapse" data-target="#warning">&times;</span>
</div>
</div>
</div>
</body>
</html>