1

Im generating a PDF in PHP with a barcode. Within the document, I need one vertical barcode and one horizontal. Heres my sample code. The barcodes generate fine.

$data = $pdf->serializeTCPDFtag('write1DBarcode', array($consignment_ID, 'C128', '', '', 165, 20, 0.4, array('position' => 'S', 'border' => false, 'padding' => 4, 'fgcolor' => array(0, 0, 0), 'bgcolor' => array(255, 255, 255), 'text' => false, 'font' => 'helvetica', 'fontsize' => 8, 'stretchtext' => 4), 'N'));

    $data2 = $pdf->serializeTCPDFtag('write1DBarcode', array($consignment_ID, 'C128', '', '', 174, 20, 0.4, array('position' => 'S', 'border' => false, 'padding' => 4, 'fgcolor' => array(0, 0, 0), 'bgcolor' => array(255, 255, 255), 'text' => false, 'font' => 'helvetica', 'fontsize' => 8, 'stretchtext' => 4), 'N'));


    $html = '<tcpdf data="' . $data . '" />';
       $html .= '<tcpdf data="' . $data2 . '" />';


    // output the HTML content
    $pdf->writeHTML($html, true, 0, true, 0);

    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



    //Close and output PDF document
    $pdf->Output('Label.pdf', 'I');

Ive tried using CSS but TCPDF doesnt not allow rotation using CSS. Is there a way to rotate the $data2 serialized tag?

Ive looked at https://tcpdf.org/examples/example_013/ but cannot see a way to apply these transformations to a serialized tag.

Heres what i have also tried;

$data = $pdf->serializeTCPDFtag('write1DBarcode', array($consignment_ID, 'C128', '', '', 165, 20, 0.4, array('position' => 'S', 'border' => false, 'padding' => 4, 'fgcolor' => array(0, 0, 0), 'bgcolor' => array(255, 255, 255), 'text' => false, 'font' => 'helvetica', 'fontsize' => 8, 'stretchtext' => 4), 'N'));

    

    $html = '
    
    <table>
    

    <tr>
        <td colspan="14" style="text-align:center;margin-top:10px;font-size:5px">&nbsp;<BR><tcpdf data="' . $data . '" /></td>
        <td colspan="2" rowspan="7">';

    $pdf->writeHTML($html, true, 0, true, 0);

    $pdf->StartTransform();
    $pdf->Rotate(-90);
    $data2 = $pdf->serializeTCPDFtag('write1DBarcode', array($consignment_ID, 'C128', '', '', 174, 20, 0.4, array('position' => 'S', 'border' => false, 'padding' => 4, 'fgcolor' => array(0, 0, 0), 'bgcolor' => array(255, 255, 255), 'text' => false, 'font' => 'helvetica', 'fontsize' => 8, 'stretchtext' => 4), 'N'));
    $html = '<tcpdf data="' . $data2 . '" />';
    $pdf->writeHTML($html, true, 0, true, 0);
    $pdf->StopTransform();

    $html = '</td>
       
    </tr>

....
OTHER COLUMNS HERE
....


</table>';


    // output the HTML content
    $pdf->writeHTML($html, true, 0, true, 0);

    // - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



    //Close and output PDF document
    $pdf->Output('Label.pdf', 'I');

6
  • Call StartTransform(), Rotate(), WriteHTML() and StopTransform() for the vertical barcode, then WriteHTML() for the horizontal one.
    – Olivier
    Commented Jun 25 at 17:33
  • The above is a shorterned version of my code. The two barcodes are shown in two different areas of a page. I usually only call writeHTML() once. Can i call this twice when rendering one page? I tried this but that didnt seem to work; $pdf->StartTransform(); $pdf->Rotate(-90); $html .= '<tcpdf data="' . $data2 . '" />'; $pdf->StopTransform();
    – Shane
    Commented Jun 25 at 17:38
  • You must call WriteHTML() before StopTransform(). And yes, you can call WriteHTML() several times.
    – Olivier
    Commented Jun 25 at 17:42
  • You can also call write1DBarcode() directly (see here).
    – Olivier
    Commented Jun 25 at 17:48
  • Thanks so much for the replies! My HTML has a Table, and the two barcodes are in different Columns. If I call writeHTML() before my tags are closed, TCPDF just returns a blank page. I will update the post to show what i tried.
    – Shane
    Commented Jun 25 at 17:58

0

Browse other questions tagged or ask your own question.