I use TCPDF to create PDF documents in PHP. Latest TCPDF supports 1D and 2D barcodes. I successfully displayed barcode as explained in the documentation like;
require_once('tcpdf_barcodes_1d.php');
$barcodeobj = new TCPDFBarcode('some_text', 'C128');
$barcode = $barcodeobj->getBarcodeHTML(1, 20, 'black');
echo $barcode;
This works fine. The barcode generated is not image, and is a combination of absolutely positioned div
s.
It also support PNG barcode generation like;
$barcodeobj->getBarcodePNG(2, 30, array(0,0,0));//displays barcode image
and SVG like;
$barcodeobj->getBarcodeSVG(2, 30, 'black');//svg file download prompt
In the case of PNG, it displays image automatically in browser. It don't need echo, or print or something else.
What I need is to print barcode into a PDF file. I use TCPDF's writeHTML()
method to create PDFs, and I want to use that method here since I have some other things to print along with barcode. How can I create PDF with barcodes in it, using writeHTML()
method (like inside an <img>
tag)?
Just use this method:
$pdf->setXY(93,272);
$pdf->write1DBarcode("074001726000003006652985", 'C39', '', '', 90, 10, 0.4, '', 'N');
Very simple, just check the documentation here: http://www.tcpdf.org/examples/example_027.phps or here http://www.tcpdf.org/doc/code/classTCPDF.html#a4816d61822a4bad6e35bb441c1699aab
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With