<?php
require 'vendor/autoload.php'; // Include Composer's autoload file
use TCPDF;

// Validate POST data
if (!isset($_POST['barcode']) || empty($_POST['barcode'])) {
    die("No barcode provided.");
}

// Create a new PDF document
$pdf = new TCPDF();
$pdf->AddPage();

// ITF-14 Barcode data
$barcode = $_POST['barcode'];

// Set Barcode style
$style = [
    'position' => '',
    'align' => 'C',
    'stretch' => false,
    'fitwidth' => true,
    'cellfitalign' => '',
    'border' => true,
    'hpadding' => 'auto',
    'vpadding' => 'auto',
    'fgcolor' => [0, 0, 0],
    'bgcolor' => false,
    'text' => true,
    'font' => 'helvetica',
    'fontsize' => 8,
    'stretchtext' => 4,
];

// Generate ITF-14 Barcode
$pdf->write1DBarcode($barcode, 'ITF', '', '', '', 30, 0.4, $style, 'N');
$pdf->Ln();
$pdf->Cell(0, 10, "Barcode: $barcode", 0, 1, 'C');

// Output the PDF
$pdf->Output('barcode.pdf', 'I');
