Pradeep Singh
Pradeep Singh

Reputation: 3634

Link on image in PDF using tcpdf

How to add hyper link on image in generated PDF using tcpdf

I am using below code to generate bar code. I want to add hyperlink on bar code.

$pdf->write2DBarcode("text goes here", 'QRCODE,H', 30, 380, 75, 75, '', 'N');

Upvotes: 1

Views: 2510

Answers (2)

beingalex
beingalex

Reputation: 2476

You can output the barcode in various formats. See the examples/barcodes directory in the framework library. One of those formats is HTML. Maybe try using that and the writeHTML method:

// You should have this file in the library:
require_once(dirname(__FILE__).'/tcpdf_barcodes_2d_include.php'); 

// set the barcode content and type
$barcodeobj = new TCPDF2DBarcode('BARCODE TEXT', 'DATAMATRIX');

// output the barcode as HTML object
$barcodeHTML = $barcodeobj->getBarcodeHTML(6, 6, 'black');

$html = '<a href="http://www.google.com">' . $barcodeHTML . '</a>';
$pdf->writeHTML($html, true, false, true, false, '');

Upvotes: 0

fdehanne
fdehanne

Reputation: 1717

You can use Link() to create a link area below your barcode.

TCPDF::Link($x, $y, $w, $h, $link, $spaces = 0)

$pdf->Link(30, 380, 75, 75, 'http://www.google.com');

Upvotes: 1

Related Questions