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

I need to print a lot of 1D and 2D barcodes and add them to an html formatted document. Looking around, I found that this is possible using TCPDF methods, indeed, example No. 49 provides a 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 implemented on my own PHP script, the barcode is not displayed. I created the test.php file, where I simply cut and pasted all the PHP code of example 49, and again just updates the contents of $ html, but has nothing specific with the $ parameters. But then again, I posted this

  $pdf->write1DBarcode(...) 

and it works perfectly, displays the barcode as expected, but as you know, this is not a way to place barcodes inside many html tables.

Any idea ?, I'm working on PHP 5.6 running on a Debian 7 server, the latest version of TCPDF. Also, I could not import tcpdf_include.php because it is included in the examples folder, tcpdf.php is used instead , and everything works fine.

Again, for clarification, I can generate both 1D and 2D barcodes using the write2DBarcode () method, but cannot generate barcodes using the generateserializeTCPDFtagParameters () method, which is recommended to place barcodes inside html, like indicated in example 49.

At @taxicaliโ€™s request, this is an approximate conclusion, it works for a local parcel company that needs accurate barcodes to be read quickly by scanners.

+5
source share
3 answers

Example TCPDF Barcode Sheet

I just solved this, which, by the way, could be a common problem: I just copied the tcpdf_config.php file, which is located here:

 /tcpdf/ examples/ config/ 

and paste here:

 /tcpdf/ config/ 

No, it was just a dependency problem.

+3
source

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 above 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); 
+2
source

Without your complete code, this can be quite difficult to solve, I worked with PDF and Barcodes some time ago, and I had a lot of problems, a lot of headaches, until I earned it. I think I should ask if your TCPDF has a font file? I think that maybe you are not including the font file, so you wonโ€™t be able to display the barcode because it needs to be rendered, another good thing: you show us the output that you get after rendering.

0
source

All Articles