|
|
|
@ -1,6 +1,14 @@
|
|
|
|
|
package com.utopiaindustries.service;
|
|
|
|
|
|
|
|
|
|
import com.google.zxing.BarcodeFormat;
|
|
|
|
|
import com.itextpdf.io.font.constants.StandardFonts;
|
|
|
|
|
import com.itextpdf.kernel.colors.ColorConstants;
|
|
|
|
|
import com.itextpdf.kernel.font.PdfFontFactory;
|
|
|
|
|
import com.itextpdf.kernel.pdf.PdfPage;
|
|
|
|
|
import com.itextpdf.kernel.pdf.canvas.PdfCanvas;
|
|
|
|
|
import com.itextpdf.layout.element.AreaBreak;
|
|
|
|
|
import com.itextpdf.layout.element.Paragraph;
|
|
|
|
|
import com.itextpdf.layout.property.TextAlignment;
|
|
|
|
|
import com.utopiaindustries.dao.ctp.*;
|
|
|
|
|
import com.utopiaindustries.model.ctp.*;
|
|
|
|
|
import com.utopiaindustries.util.BarcodeUtils;
|
|
|
|
@ -12,8 +20,19 @@ import com.zebra.sdk.printer.ZebraPrinter;
|
|
|
|
|
import com.zebra.sdk.printer.ZebraPrinterFactory;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import com.itextpdf.io.image.ImageDataFactory;
|
|
|
|
|
import com.itextpdf.kernel.pdf.PdfDocument;
|
|
|
|
|
import com.itextpdf.kernel.geom.PageSize;
|
|
|
|
|
import com.itextpdf.kernel.pdf.PdfWriter;
|
|
|
|
|
import com.itextpdf.layout.Document;
|
|
|
|
|
import com.itextpdf.layout.element.Image;
|
|
|
|
|
import javax.imageio.ImageIO;
|
|
|
|
|
import java.awt.image.BufferedImage;
|
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
|
|
import java.nio.file.Path;
|
|
|
|
|
import java.nio.file.FileSystems;
|
|
|
|
|
import javax.imageio.ImageIO;
|
|
|
|
|
|
|
|
|
|
import java.awt.*;
|
|
|
|
|
import java.awt.Font;
|
|
|
|
|
import java.awt.geom.AffineTransform;
|
|
|
|
@ -22,6 +41,7 @@ import java.io.*;
|
|
|
|
|
|
|
|
|
|
import java.nio.file.FileSystems;
|
|
|
|
|
import java.nio.file.Path;
|
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import com.google.zxing.EncodeHintType;
|
|
|
|
@ -48,13 +68,17 @@ public class BarcodeService {
|
|
|
|
|
private final MasterBundleDAO masterBundleDAO;
|
|
|
|
|
private final FinishedItemDAO finishedItemDAO;
|
|
|
|
|
private final StitchingOfflineItemDAO stitchingOfflineItemDAO;
|
|
|
|
|
private final InventoryAccountDAO inventoryAccountDAO;
|
|
|
|
|
private final JobCardItemDAO jobCardItemDAO;
|
|
|
|
|
|
|
|
|
|
public BarcodeService(BundleDAO bundleDAO, JobCardDAO jobCardDAO, MasterBundleDAO masterBundleDAO, FinishedItemDAO finishedItemDAO, StitchingOfflineItemDAO stitchingOfflineItemDAO) {
|
|
|
|
|
public BarcodeService(BundleDAO bundleDAO, JobCardDAO jobCardDAO, MasterBundleDAO masterBundleDAO, FinishedItemDAO finishedItemDAO, StitchingOfflineItemDAO stitchingOfflineItemDAO, InventoryAccountDAO inventoryAccountDAO, JobCardItemDAO jobCardItemDAO) {
|
|
|
|
|
this.bundleDAO = bundleDAO;
|
|
|
|
|
this.jobCardDAO = jobCardDAO;
|
|
|
|
|
this.masterBundleDAO = masterBundleDAO;
|
|
|
|
|
this.finishedItemDAO = finishedItemDAO;
|
|
|
|
|
this.stitchingOfflineItemDAO = stitchingOfflineItemDAO;
|
|
|
|
|
this.inventoryAccountDAO = inventoryAccountDAO;
|
|
|
|
|
this.jobCardItemDAO = jobCardItemDAO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
@ -83,131 +107,186 @@ public class BarcodeService {
|
|
|
|
|
BarcodeStickerSize stickerSize,
|
|
|
|
|
String artifactType) throws Exception {
|
|
|
|
|
|
|
|
|
|
for (InventoryArtifact artifact : artifacts) {
|
|
|
|
|
// Create a blank BufferedImage (an image with the size of the sticker)
|
|
|
|
|
BufferedImage stickerImage = new BufferedImage((int) stickerSize.getWidth()*2, (int) stickerSize.getHeight()*2, BufferedImage.TYPE_INT_ARGB);
|
|
|
|
|
Graphics2D g2d = stickerImage.createGraphics();
|
|
|
|
|
g2d.scale(2,2);
|
|
|
|
|
|
|
|
|
|
int pageWidth = 900; // A4 Width
|
|
|
|
|
int pageHeight = 1200; // A4 Height
|
|
|
|
|
|
|
|
|
|
int rows = 3;
|
|
|
|
|
int cols = 2;
|
|
|
|
|
int totalStickersPerPage = rows * cols;
|
|
|
|
|
|
|
|
|
|
int totalPages = (int) Math.ceil((double) artifacts.size() / totalStickersPerPage); // Total required pages
|
|
|
|
|
|
|
|
|
|
for (int page = 0; page < totalPages; page++) {
|
|
|
|
|
// Create a Blank A4 Page Image
|
|
|
|
|
BufferedImage a4Image = new BufferedImage(pageWidth, pageHeight, BufferedImage.TYPE_INT_ARGB);
|
|
|
|
|
Graphics2D g2d = a4Image.createGraphics();
|
|
|
|
|
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|
|
|
|
|
|
|
|
|
// Set background color (white for the sticker)
|
|
|
|
|
g2d.setColor(Color.WHITE);
|
|
|
|
|
g2d.fillRect(0, 0, (int) stickerSize.getWidth(), (int) stickerSize.getHeight());
|
|
|
|
|
g2d.fillRect(0, 0, pageWidth, pageHeight);
|
|
|
|
|
g2d.setColor(Color.BLACK);
|
|
|
|
|
|
|
|
|
|
// Set font for SKU and barcode
|
|
|
|
|
Font font = new Font("Helvetica", Font.BOLD, stickerSize.getTextSize()+10);
|
|
|
|
|
g2d.setFont(font);
|
|
|
|
|
|
|
|
|
|
// Add SKU to the image
|
|
|
|
|
Font barcodeFont = new Font("Helvetica", Font.BOLD, stickerSize.getTextSize()+8);
|
|
|
|
|
Font detailFont = new Font("Helvetica", Font.PLAIN, stickerSize.getTextSize()+3);
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < totalStickersPerPage; i++) {
|
|
|
|
|
int artifactIndex = page * totalStickersPerPage + i;
|
|
|
|
|
if (artifactIndex >= artifacts.size()) break;
|
|
|
|
|
InventoryArtifact artifact = artifacts.get(artifactIndex);
|
|
|
|
|
int row = i / cols;
|
|
|
|
|
int col = i % cols;
|
|
|
|
|
|
|
|
|
|
int x = col * (pageWidth / cols);
|
|
|
|
|
int y = row * (pageHeight / rows);
|
|
|
|
|
|
|
|
|
|
Font stickerFont = new Font("Helvetica", Font.BOLD, stickerSize.getTextSize() + 10);
|
|
|
|
|
g2d.setFont(stickerFont);
|
|
|
|
|
// Draw Sticker Border
|
|
|
|
|
g2d.drawRect(x, y, pageWidth / cols, pageHeight / rows);
|
|
|
|
|
|
|
|
|
|
this.drawCenteredText(g2d, artifactType.equals("Bundle")?"Sub-Bundle":"Master-Bundle", detailFont, x, y, pageWidth, cols, stickerSize.getMarginTop()-20,stickerSize.getMarginLeft()-165);
|
|
|
|
|
|
|
|
|
|
// Draw SKU
|
|
|
|
|
g2d.setFont(barcodeFont);
|
|
|
|
|
String sku = artifact.getSku();
|
|
|
|
|
FontMetrics fontMetrics = g2d.getFontMetrics();
|
|
|
|
|
int textWidth = fontMetrics.stringWidth(sku);
|
|
|
|
|
int x = (int) ((stickerSize.getWidth() - textWidth) / 2);
|
|
|
|
|
g2d.setColor(Color.BLACK);
|
|
|
|
|
g2d.drawString(sku, x, stickerSize.getMarginTop() + fontMetrics.getAscent()+20);
|
|
|
|
|
g2d.drawString(sku, x + ((pageWidth / cols) - textWidth) / 2, y + fontMetrics.getAscent()+ stickerSize.getMarginTop()+10);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Generate Barcode Image
|
|
|
|
|
g2d.setFont(barcodeFont);
|
|
|
|
|
byte[] imgBytes = BarcodeUtils.getBarcodeImageByteArray(
|
|
|
|
|
artifact.getBarcode(), BarcodeFormat.CODE_128, stickerSize.getImageWidthBarcode(), stickerSize.getImageHeightBarcode());
|
|
|
|
|
|
|
|
|
|
// Create the barcode image
|
|
|
|
|
byte[] imgBytes = BarcodeUtils.getBarcodeImageByteArray(artifact.getBarcode(), BarcodeFormat.CODE_128, stickerSize.getImageWidthBarcode()+500, stickerSize.getImageHeightBarcode()+30);
|
|
|
|
|
BufferedImage barcodeImage = ImageIO.read(new ByteArrayInputStream(imgBytes));
|
|
|
|
|
int originalBarcodeWidth = barcodeImage.getWidth();
|
|
|
|
|
int originalBarcodeHeight = barcodeImage.getHeight();
|
|
|
|
|
|
|
|
|
|
// Draw the barcode image on the sticker
|
|
|
|
|
int barcodeX =(int) (stickerSize.getWidth() - barcodeImage.getWidth()) / 2;
|
|
|
|
|
int barcodeY = stickerSize.getMarginTop() + fontMetrics.getAscent() + 30; // Add some margin
|
|
|
|
|
g2d.drawImage(barcodeImage, barcodeX, barcodeY, null);
|
|
|
|
|
|
|
|
|
|
// Add the barcode value below the barcode image
|
|
|
|
|
g2d.drawString(artifact.getBarcode(), (stickerSize.getWidth() - fontMetrics.stringWidth(artifact.getBarcode())) / 2,
|
|
|
|
|
barcodeY + barcodeImage.getHeight() + fontMetrics.getAscent());
|
|
|
|
|
double scaleX = (double)(pageWidth / cols) / originalBarcodeWidth;
|
|
|
|
|
double scaleY = (double)(pageHeight / rows) / originalBarcodeHeight;
|
|
|
|
|
double scaleFactor = Math.min(scaleX, scaleY);
|
|
|
|
|
|
|
|
|
|
// If artifactType is Bundle, add additional info
|
|
|
|
|
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() + 45);
|
|
|
|
|
int scaledWidth = (int)(originalBarcodeWidth * scaleFactor) - 30;
|
|
|
|
|
int scaledHeight = (int)(originalBarcodeHeight * scaleFactor) - 10;
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
BufferedImage scaledBarcodeImage = new BufferedImage(scaledWidth, scaledHeight, BufferedImage.TYPE_INT_ARGB);
|
|
|
|
|
Graphics2D g2dBarcode = scaledBarcodeImage.createGraphics();
|
|
|
|
|
g2dBarcode.drawImage(barcodeImage, 0, 0, scaledWidth, scaledHeight, null);
|
|
|
|
|
g2dBarcode.dispose();
|
|
|
|
|
|
|
|
|
|
int barcodeX = x + ((pageWidth / cols) - scaledBarcodeImage.getWidth()) / 2;
|
|
|
|
|
int barcodeY = y + fontMetrics.getAscent() + stickerSize.getMarginTop() + 20;
|
|
|
|
|
g2d.drawImage(scaledBarcodeImage, barcodeX, barcodeY, null);
|
|
|
|
|
|
|
|
|
|
//barcode text
|
|
|
|
|
g2d.setFont(barcodeFont);
|
|
|
|
|
String barcode = artifact.getBarcode();
|
|
|
|
|
FontMetrics barcodeFontMatrix = g2d.getFontMetrics();
|
|
|
|
|
int barcodeText = fontMetrics.stringWidth(barcode);
|
|
|
|
|
g2d.drawString(barcode, (x + ((pageWidth / cols) - barcodeText) / 2), y + barcodeFontMatrix.getAscent() + stickerSize.getMarginTop() + 120);
|
|
|
|
|
|
|
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy hh:mm");
|
|
|
|
|
this.drawCenteredText(g2d, "Item-ID: "+artifact.getItemId(), detailFont, x, y, pageWidth, cols, stickerSize.getMarginTop() + 150,stickerSize.getMarginLeft());
|
|
|
|
|
this.drawCenteredText(g2d, "Created-By: "+artifact.getCreatedBy(), detailFont, x, y, pageWidth, cols, stickerSize.getMarginTop() + 170,stickerSize.getMarginLeft());
|
|
|
|
|
this.drawCenteredText(g2d, "Created-At: "+formatter.format(artifact.getCreatedAt()), detailFont, x, y, pageWidth, cols, stickerSize.getMarginTop() + 190,stickerSize.getMarginLeft());
|
|
|
|
|
|
|
|
|
|
//draw job-card details
|
|
|
|
|
JobCard jobCard = jobCardDAO.find(artifact.getJobCardId());
|
|
|
|
|
|
|
|
|
|
this.drawCenteredText(g2d, "Job-Card: " + jobCard.getCode(), detailFont, x, y, pageWidth, cols, stickerSize.getMarginTop() + 210, stickerSize.getMarginLeft() );
|
|
|
|
|
this.drawCenteredText(g2d, "Purchase-Order: " + jobCard.getPurchaseOrderId(), detailFont, x, y, pageWidth, cols, stickerSize.getMarginTop() + 230, stickerSize.getMarginLeft());
|
|
|
|
|
this.drawCenteredText(g2d, "Lot-Number: " + jobCard.getLotNumber(), detailFont, x, y, pageWidth, cols, stickerSize.getMarginTop() + 250, stickerSize.getMarginLeft());
|
|
|
|
|
if((artifactType.equals("Bundle"))){
|
|
|
|
|
JobCardItem jobCardItem = jobCardItemDAO.findByCardId(jobCard.getId()).get(0);
|
|
|
|
|
InventoryAccount inventoryAccount = inventoryAccountDAO.find(jobCardItem.getAccountId());
|
|
|
|
|
this.drawCenteredText(g2d, "Pieces: " + artifact.getWrapQuantity(), detailFont, x, y, pageWidth, cols, stickerSize.getMarginTop() + 270, stickerSize.getMarginLeft());
|
|
|
|
|
this.drawCenteredText(g2d, "Cutting-Account: " + inventoryAccount.getTitle() , detailFont, x, y, pageWidth, cols, stickerSize.getMarginTop() + 290, stickerSize.getMarginLeft());
|
|
|
|
|
}else {
|
|
|
|
|
// Add first character of artifact type
|
|
|
|
|
String type = String.valueOf(artifactType.charAt(0));
|
|
|
|
|
g2d.setFont(new Font("Helvetica", Font.BOLD, stickerSize.getTextSize()+10));
|
|
|
|
|
g2d.drawString(type, (stickerSize.getWidth() - fontMetrics.stringWidth(type)) / 2,
|
|
|
|
|
barcodeY + barcodeImage.getHeight() + fontMetrics.getAscent() + 45);
|
|
|
|
|
List<Bundle> bundles = bundleDAO.findByMasterId(artifact.getId());
|
|
|
|
|
String concatenatedIds = bundles.stream()
|
|
|
|
|
.map(bundle -> String.valueOf(bundle.getId()))
|
|
|
|
|
.collect(Collectors.joining("\\"));
|
|
|
|
|
|
|
|
|
|
this.drawCenteredText(g2d, "Sub-Bundles: " + concatenatedIds, detailFont, x, y, pageWidth, cols, stickerSize.getMarginTop() + 290, stickerSize.getMarginLeft());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Finalize drawing
|
|
|
|
|
|
|
|
|
|
this.drawCenteredText(g2d, String.valueOf(artifact.getId()), detailFont, x, y, pageWidth, cols, stickerSize.getMarginTop() + 330, 0);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Finalize Drawing
|
|
|
|
|
g2d.dispose();
|
|
|
|
|
printLabel(stickerImage);
|
|
|
|
|
|
|
|
|
|
// Save A4 Page as PNG
|
|
|
|
|
Path path = FileSystems.getDefault().getPath("./src/main/resources/static/barcode_a4_" + (page + 1) + ".png");
|
|
|
|
|
File outputFile = path.toFile();
|
|
|
|
|
ImageIO.write(a4Image, "PNG", outputFile);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//use for detail heading
|
|
|
|
|
private void drawCenteredText(Graphics2D g2d, String text, Font font, int x, int y, int pageWidth, int cols, int marginTop, int marginLeft) {
|
|
|
|
|
g2d.setFont(font);
|
|
|
|
|
FontMetrics fontMetrics = g2d.getFontMetrics();
|
|
|
|
|
int adjustedX = (x + ((pageWidth / cols) ) / 2) - marginLeft;
|
|
|
|
|
int adjustedY = y + fontMetrics.getAscent() + marginTop;
|
|
|
|
|
g2d.drawString(text, adjustedX, adjustedY);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void getBarcodeImagesForStitchItems(List<? extends InventoryArtifact> artifacts,
|
|
|
|
|
BarcodeStickerSize stickerSize,
|
|
|
|
|
String artifactType) throws Exception {
|
|
|
|
|
|
|
|
|
|
Path pdfPath = FileSystems.getDefault().getPath("./src/main/resources/static/sample_qr_output.pdf");
|
|
|
|
|
PdfWriter writer = new PdfWriter(pdfPath.toFile());
|
|
|
|
|
|
|
|
|
|
PdfDocument pdfDoc = new PdfDocument(writer);
|
|
|
|
|
Document document = new Document(pdfDoc);
|
|
|
|
|
|
|
|
|
|
pdfDoc.setDefaultPageSize(new PageSize(stickerSize.getWidth(), stickerSize.getHeight()));
|
|
|
|
|
|
|
|
|
|
for (InventoryArtifact artifact : artifacts) {
|
|
|
|
|
JobCard jobCard = jobCardDAO.find(artifact.getJobCardId());
|
|
|
|
|
List<Bundle> bundles = bundleDAO.findByItemIdAndCardId(artifact.getItemId(), jobCard.getId());
|
|
|
|
|
String concatenatedIds = bundles.stream()
|
|
|
|
|
.map(bundle -> String.valueOf(bundle.getId()))
|
|
|
|
|
.collect(Collectors.joining("\\"));
|
|
|
|
|
// Set Portrait Mode Dimensions
|
|
|
|
|
int stickerWidth = (int) stickerSize.getWidth();
|
|
|
|
|
int stickerHeight = (int) stickerSize.getHeight();
|
|
|
|
|
|
|
|
|
|
BufferedImage stickerImage = new BufferedImage(stickerWidth * 2, stickerHeight * 2, BufferedImage.TYPE_INT_ARGB);
|
|
|
|
|
Graphics2D g2d = stickerImage.createGraphics();
|
|
|
|
|
g2d.scale(2, 2);
|
|
|
|
|
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|
|
|
|
// **Add New Page for Each Artifact**
|
|
|
|
|
PdfPage page = pdfDoc.addNewPage();
|
|
|
|
|
PdfCanvas canvas = new PdfCanvas(page);
|
|
|
|
|
|
|
|
|
|
g2d.setColor(Color.WHITE);
|
|
|
|
|
g2d.fillRect(0, 0, stickerWidth, stickerHeight);
|
|
|
|
|
// **Set Background White**
|
|
|
|
|
canvas.setFillColor(ColorConstants.WHITE);
|
|
|
|
|
canvas.rectangle(0, 0, stickerSize.getWidth(), stickerSize.getHeight());
|
|
|
|
|
canvas.fill();
|
|
|
|
|
|
|
|
|
|
// Draw Stitch Line (Dotted Line at the Top)
|
|
|
|
|
String stitchLine = "|";
|
|
|
|
|
Font fontLine = new Font("Helvetica", Font.BOLD, stickerSize.getTextSize()-2);
|
|
|
|
|
g2d.setFont(fontLine);
|
|
|
|
|
FontMetrics fontMetricsLine = g2d.getFontMetrics();
|
|
|
|
|
int textWidthLine = fontMetricsLine.stringWidth(stitchLine);
|
|
|
|
|
int centerXLine = stickerSize.getMarginLeft();
|
|
|
|
|
g2d.setColor(Color.BLACK);
|
|
|
|
|
for(int i=0;i<16;i++){
|
|
|
|
|
g2d.drawString(stitchLine, centerXLine,5+(i*3));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Draw ID Below Stitch Line
|
|
|
|
|
String id = String.valueOf(artifact.getId());
|
|
|
|
|
g2d.setFont(new Font("Helvetica", Font.BOLD, stickerSize.getTextSize()));
|
|
|
|
|
FontMetrics fontMetricsId = g2d.getFontMetrics();
|
|
|
|
|
int textHeightId = fontMetricsId.getHeight();
|
|
|
|
|
int centerXID = stickerSize.getMarginLeft()+7;
|
|
|
|
|
int centerYID = (stickerHeight / 2) + (textHeightId / 4);
|
|
|
|
|
AffineTransform originalTransform = g2d.getTransform();
|
|
|
|
|
g2d.rotate(Math.toRadians(-90), centerXID, centerYID);
|
|
|
|
|
g2d.drawString(id, centerXID, centerYID);
|
|
|
|
|
g2d.setTransform(originalTransform);
|
|
|
|
|
|
|
|
|
|
// Draw QR Code Below the ID
|
|
|
|
|
// **Draw QR Code on Left Side**
|
|
|
|
|
byte[] imgBytes = generateQRCodeImageByteArray(artifact.getBarcode(), stickerSize.getImageWidthBarcode(), stickerSize.getImageHeightBarcode());
|
|
|
|
|
BufferedImage qrCodeImage = ImageIO.read(new ByteArrayInputStream(imgBytes));
|
|
|
|
|
Image qrCodeImage = new Image(ImageDataFactory.create(imgBytes));
|
|
|
|
|
|
|
|
|
|
int centerXQR = stickerSize.getMarginLeft()-12;
|
|
|
|
|
int centerYQR = (stickerHeight / 2) + (textHeightId / 2)+1;
|
|
|
|
|
AffineTransform originalTransformQR = g2d.getTransform();
|
|
|
|
|
g2d.rotate(Math.toRadians(-90), centerXID, centerYID);
|
|
|
|
|
g2d.drawImage(qrCodeImage, centerXQR, centerYQR, null);
|
|
|
|
|
g2d.setTransform(originalTransformQR);
|
|
|
|
|
float qrX =stickerSize.getMarginLeft() ;
|
|
|
|
|
float qrY = stickerSize.getMarginTop();
|
|
|
|
|
|
|
|
|
|
// Prepare Text Lines Below QR Code
|
|
|
|
|
qrCodeImage.setFixedPosition(qrX + 15, qrY-12);
|
|
|
|
|
document.add(qrCodeImage);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float textX = stickerSize.getMarginLeft() + 40;
|
|
|
|
|
float textY = stickerSize.getMarginTop() +40;
|
|
|
|
|
|
|
|
|
|
// **Prepare Text Lines**
|
|
|
|
|
String sku = artifact.getSku();
|
|
|
|
|
String jobCardCode = jobCard.getCode();
|
|
|
|
|
String combinedText = sku + " \\" + jobCardCode + concatenatedIds;
|
|
|
|
|
|
|
|
|
|
int maxLength = 16; // Max characters per line
|
|
|
|
|
int maxLength = 16;
|
|
|
|
|
List<String> lines = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
|
int start = i * maxLength;
|
|
|
|
|
if (start < combinedText.length()) {
|
|
|
|
@ -215,34 +294,51 @@ public class BarcodeService {
|
|
|
|
|
lines.add(part);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
g2d.rotate(Math.toRadians(-90), stickerWidth / 2, stickerHeight / 2);
|
|
|
|
|
|
|
|
|
|
// Draw Rotated Text Below QR Code
|
|
|
|
|
g2d.setColor(Color.BLACK);
|
|
|
|
|
g2d.setFont(new Font("Helvetica", Font.BOLD, stickerSize.getTextSize()));
|
|
|
|
|
FontMetrics fontMetrics = g2d.getFontMetrics();
|
|
|
|
|
int lineHeight = fontMetrics.getHeight();
|
|
|
|
|
int centerXSKU = stickerSize.getMarginLeft()+4;
|
|
|
|
|
int centerYSKU = (stickerHeight / 2) + (textHeightId / 4)+20;
|
|
|
|
|
// **Draw Rotated Text to the Right of QR Code**
|
|
|
|
|
float lineX = textX-30;
|
|
|
|
|
for (String line : lines) {
|
|
|
|
|
Paragraph rotatedText = new Paragraph(line)
|
|
|
|
|
.setBold()
|
|
|
|
|
.setFontColor(ColorConstants.BLACK) // ✅ Text Color
|
|
|
|
|
.setFontSize(stickerSize.getTextSize())
|
|
|
|
|
.setTextAlignment(TextAlignment.LEFT)
|
|
|
|
|
.setFixedPosition( lineX, textY+5, 200)
|
|
|
|
|
.setRotationAngle(-Math.PI / 2); // ✅ -90 Degree Rotate
|
|
|
|
|
|
|
|
|
|
AffineTransform originalTransformSKu = g2d.getTransform();
|
|
|
|
|
g2d.rotate(Math.toRadians(-0.1), centerXSKU, centerYSKU);
|
|
|
|
|
for (int i = 0; i < lines.size(); i++) {
|
|
|
|
|
int lineWidth = fontMetrics.stringWidth(lines.get(i));
|
|
|
|
|
g2d.drawString(lines.get(i), (stickerWidth - lineWidth) / 2, centerYSKU + (i * lineHeight));
|
|
|
|
|
document.add(rotatedText);
|
|
|
|
|
lineX -= 5; // ✅ Line Gap
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g2d.setTransform(originalTransformSKu);
|
|
|
|
|
String id = String.valueOf(artifact.getId());
|
|
|
|
|
document.add(new Paragraph(id)
|
|
|
|
|
.setFontSize(stickerSize.getTextSize())
|
|
|
|
|
.setBold()
|
|
|
|
|
.setRotationAngle(-Math.PI / 2)
|
|
|
|
|
.setTextAlignment(TextAlignment.LEFT)
|
|
|
|
|
.setFixedPosition(textX + 30, textY-16, 100));
|
|
|
|
|
|
|
|
|
|
g2d.dispose();
|
|
|
|
|
float dottedLine = textY - 50;
|
|
|
|
|
for(int i= 0 ;i<16;i++){
|
|
|
|
|
document.add(new Paragraph("|")
|
|
|
|
|
.setFontSize(stickerSize.getTextSize())
|
|
|
|
|
.setBold()
|
|
|
|
|
.setTextAlignment(TextAlignment.LEFT)
|
|
|
|
|
.setFixedPosition(textX + 47, dottedLine, 100));
|
|
|
|
|
|
|
|
|
|
// Save Image
|
|
|
|
|
Path path = FileSystems.getDefault().getPath("./src/main/resources/static/sample_qr.png");
|
|
|
|
|
File outputFile = path.toFile();
|
|
|
|
|
ImageIO.write(stickerImage, "PNG", outputFile);
|
|
|
|
|
dottedLine += 10;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
document.add(new AreaBreak());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
document.close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public byte[] generateQRCodeImageByteArray(String data, int width, int height) {
|
|
|
|
|
try {
|
|
|
|
|