diff --git a/app/Services/StickerPdfService.php b/app/Services/StickerPdfService.php index 5c568a26..9649dcf2 100644 --- a/app/Services/StickerPdfService.php +++ b/app/Services/StickerPdfService.php @@ -1614,29 +1614,8 @@ class StickerPdfService $stickerHeight = (float) $template['height']; $stickerId = $template['sticker_id'] ?? null; - // $gap = 5.0; - - // $count = ($toSerial - $fromSerial) + 1; - - // $totalHeight = - // ($stickerHeight * $count) - // + - // ($gap * ($count - 1)); - $orientation = $stickerWidth > $stickerHeight ? 'L' : 'P'; - // $pdf = new TCPDF( - // 'P', - // 'mm', - // [ - // $stickerWidth, - // $stickerHeight - // ], - // true, - // 'UTF-8', - // false - // ); - $pdf = new TCPDF($orientation, 'mm', [$stickerWidth, $stickerHeight], true, 'UTF-8', false); $pdf->setPrintHeader(false); @@ -1714,6 +1693,18 @@ class StickerPdfService $pdf->SetFont($element['font'], '', $element['size']); + $font = $element['font'] ?? 'helvetica'; + $fontSize = (float) ($element['size'] ?? 10); + + // if ( + // ($element['characteristics_type'] ?? '') == 'feed_address' + // && mb_strlen((string) $textValue) > 61 + // ) { + // $fontSize = max(6, $fontSize - 2); + // } + + $pdf->SetFont($font, '', $fontSize); + $x = (float) $element['x']; $y = $element['y'] + $currentY; @@ -1737,7 +1728,22 @@ class StickerPdfService $x = $leftMargin; } } + if($stickerId == 'SelfPriming Monoblock Pump'){ + $leftMargin = 10; + $rightMargin = 10; + $usableWidth = 85 - $leftMargin - $rightMargin; // 65mm + + $textWidth = $pdf->GetStringWidth((string) $textValue); + + // Center the address within the available width + $x = $leftMargin + (($usableWidth - $textWidth) / 2); + + // Prevent the address from starting before the left margin + if ($textWidth > $usableWidth) { + $x = $leftMargin; + } + } } $pdf->Text($x, $y, (string) $textValue);