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"> <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');
StartTransform()
,Rotate()
,WriteHTML()
andStopTransform()
for the vertical barcode, thenWriteHTML()
for the horizontal one.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();
WriteHTML()
beforeStopTransform()
. And yes, you can callWriteHTML()
several times.write1DBarcode()
directly (see here).writeHTML()
before my tags are closed, TCPDF just returns a blank page. I will update the post to show what i tried.