labeltcpdfcustom-pages

tcpdf create a label pdf size width:57mm and height:32mm


guys i use TCPDF library for my php server and i want to create a label with width:57mm and height:32mm

$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetPrintHeader(false);
$pdf->SetPrintFooter(false);
$pdf->AddPage('L', array(57,32));
$pdf->SetFont('dejavusans');
$html ="
    <table class='domi'>
    <tbody >";
    for($i=0; $i<$rows; $i++){
        $style=' style="font-size:'.$fontsize[0][$i].'px"';
        if($bold[0][$i]===0){
            $html2a[$i] = "<tr><td".$style.">".$content_line[$i]."</td></tr>";
        } else {
            $html2a[$i] = "<tr><td".$style."><b>".$content_line[$i]."</b></td></tr>";
        }
        $html2b .= $html2a[$i];//$pdf->GetStringWidth($html2a[$i])." ";
    }
    $html3 = "</tbody>
    </table>";
$pdf->writeHTMLCell($w=55, $h=2, $x='1', $y='1', $html.$html2b.$html3, $border=1, $ln=1, $fill=0, $reseth=false, $align='C', $autopadding=true);
$pdf->Output($_SERVER['DOCUMENT_ROOT'] . 'Site/labels/label'.$id.'.pdf', 'FI');

1st of all it prints the contents fine from the database in A4 size etc but all i want is to create and save the pdf document in the label size width:57mm and height:32mm!!! https://i.sstatic.net/kQ8Be.png

as you see, I've marked with 1-5 numbers the actual data and the rest are marked with questionmarks!! I dont understand why of course.

2nd when i change the line $pdf->AddPage('L', array(57,32)); to $pdf->AddPage('L', array(57,57)); the label is created but i have an empty space in the bottom-right corner + it doesnt have the 32x57 size!!! https://i.sstatic.net/XgEWU.png

thanks in advance!!!


Solution

  • it seems that i had missconfigured my TCPDF library... the simple solution that i came up was to put this line

    $pdf->SetAutoPageBreak(true, 0);
    

    after this

    $pdf->SetFont('dejavusans');
    

    and the result was perfect!!!

    https://i.sstatic.net/hGwyR.png <-perfectly configured label

    https://i.sstatic.net/khs9v.png <-wrongly configured label but in my case it perfect for the job!!! all i want is to preview the result before saving (i mean saving the wrong configuration and then update the base until the configuration is good!!)