tcpdf getBarcodeHTML and writeHtml

Roberto S
  • Roberto S

    Roberto S - 2014-01-15

    hi, i am trying to use an html qr barcode generated with tcpdf and put it into a PDF with writeHTML but it doesn't seems to work.

    is this expected?

    the only workaround is to put the barcode generation (png) in one separate php file and make a file_get_contents to save it to file disk?

    it would be welcome a method for writing the file directly to disk. the ob_start-ob_get_contents is not wrking because the getBarcodePNG seems to be sending some headers.

    thanks in advance!

  • Lubos Dz

    Lubos Dz - 2014-01-16

    Thumb up - I reported same issue about a 1-2 weeks ago, but no response.
    You need to modify slightly in file

    to skip outputing headers, which are hard-coded. I simply added argument $addHeaders:

    public function getBarcodePNG($w=3, $h=3, $color=array(0,0,0), $addHeaders = true) {
        header('Content-Type: image/png');
        header('Cache-Control: public, must-revalidate, max-age=0'); // HTTP/1.1
        header('Pragma: public');
        header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
        header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');

    It's wrong dirty way of solving the issue, but it may take time to wait for another solution:-)

  • Nicola Asuni

    Nicola Asuni - 2014-01-16

    Barcodes can be directly added to the PDF document without converting them in png format. The native vector format is smaller in size and preserve the quality.
    Alternatively you can call the TCPDF methods in HTML (example n. 49), or use the SVG format with the img tag.


Log in to post a comment.