How to create pdf barcode using writeHTML () method - TCPDF

I use TCPDF to create PDF documents in PHP. The latest TCPDF supports 1D and 2D barcodes. I successfully displayed the barcode as described in the documentation, for example:

require_once('tcpdf_barcodes_1d.php'); $barcodeobj = new TCPDFBarcode('some_text', 'C128'); $barcode = $barcodeobj->getBarcodeHTML(1, 20, 'black'); echo $barcode; 

It works great. The generated barcode is not an image and is a combination of absolutely positioned div s.

It also supports the creation of PNG barcodes, for example:

 $barcodeobj->getBarcodePNG(2, 30, array(0,0,0));//displays barcode image 

and SVG, for example:

 $barcodeobj->getBarcodeSVG(2, 30, 'black');//svg file download prompt 

In the case of PNG, it automatically displays the image in the browser. She doesn't need an echo, or a seal, or anything else.

I need to print a barcode in a PDF file. I use the TCPDF writeHTML() method to create PDF files, and I want to use this method here, since I have other things to print along with the barcode. How can I create a PDF with barcodes in it using the writeHTML() method (for example, inside the <img> )?

Thanks in advance ... :)

+4
source share
1 answer

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

+2
source

Source: https://habr.com/ru/post/1493625/


All Articles