Reputation: 1842
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.
Upvotes: 6
Views: 9815
Reputation: 21
<?php
$params = $pdf->serializeTCPDFtagParameters(array('5027010247321', 'C39', '', '', 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'));
?>
And paste these below line where you want tcpdf baarcode
" />Visit https://www.youtube.com/watch?v=flXFPbKRmUo
Upvotes: 0
Reputation: 2020
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);
Upvotes: 8
Reputation: 1842
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.
Upvotes: 5
Reputation: 21759
Without your full code, it may be pretty difficult to tackle this down, I've worked with PDF and Barcodes a while ago and had a lot of issues, many headaches untill I made it work. One think I have to ask, does your TCPDF come with a font file? I think that maybe you are not including the font file thus you wont be able to render the barcode as it should be rendered, another good thing would be that You show us the output you are getting post-render.
Upvotes: 0