Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to place TCPDF barcodes inside a html table using example 49 and serializeTCPDFtagParameters instead of write1DBarcode?

I need to print many 1D and 2D barcodes and plce them inside a html formatted doc. Looking around I found that this is possible using TCPDF methods, indeed the example No.49 gives the solution.

$params = $pdf->serializeTCPDFtagParameters(array('CODE 128', 'C128', '', '', 80, 30, 0.4, array('position'=>'S', 'border'=>true, 'padding'=>4, 'fgcolor'=>array(0,0,0), 'bgcolor'=>array(255,255,255), 'text'=>true, 'font'=>'helvetica', 'fontsize'=>8, 'stretchtext'=>4), 'N'));
$html .= '<tcpdf method="write1DBarcode" params="'.$params.'" />';

However when implementing on my own PHP script, no barcode is rendered. I created a test.php file where just cut and pasted the whole 49 example php code, and again just reders the $html content, but not anything defined with $params.
But again, I placed this

 $pdf->write1DBarcode(...)

and works perfect, renders the barcode as expected, but as you may know, this is not the way to place barcodes inside many html tables.

Any idea?, I'm working on PHP 5.6 running on a Debian 7 server, TCPDF latest version. Also I couldn't import the tcpdf_include.php, because it comes inside the examples folder, instead have used the tcpdf.php and everything is working ok.

Again, and to clarify, I can generate both 1D and 2D barcodes using the write2DBarcode() method, but cannot generate barcodes using the generateserializeTCPDFtagParameters() method which is the recommended one to place barcodes inside html as stated in example 49.

By request of @taxicali, this is a sample output, works for a local parcel company which needs accurate barcodes in order to be quickly read by scanners.

like image 635
digitai Avatar asked May 22 '15 17:05

digitai


2 Answers

To use the tcpdf html tag you need to set the constant 'K_TCPDF_CALLS_IN_HTML' to 'TRUE' in the tcpdf_config.php file, as the example says at the top in red

https://tcpdf.org/examples/example_049/

/**
 * If true allows to call TCPDF methods using HTML syntax
 * IMPORTANT: For security reason, disable this feature if you are printing user HTML content.
 */
define('K_TCPDF_CALLS_IN_HTML', true);
like image 144
webmaster Avatar answered Nov 11 '22 11:11

webmaster


Sample of a barcodes sheet generated by TCPDF

I just solved this which by the way can be a common issue: I just copied the tcpdf_config.php file that is located here:

/tcpdf/
      examples/
              config/

and pasted here:

/tcpdf/
      config/

No more, it was just a problem of dependencies.

like image 5
digitai Avatar answered Nov 11 '22 10:11

digitai