Jeremy Dicaire
Jeremy Dicaire

Reputation: 4905

How to use TCPDF to generate a PDF417 2D barcode?

I recently found the TCPDF library to generate PDF with PHP.

A method to generate 2D barcode is also included.

I want to use this feature to generate PDF417 ad Aztec barcode without generating a PDF file. (Like saving it to a file (PMG. SVG, etc) I looked at the included files to see if I can find the code I need, but I didn't find anything.

On the website, akk the exemples are based on the fact that people want a PDF file... I jsut want the image :)

Any suggestion? I don't want to pay 400$ for a barcode :(

Upvotes: 2

Views: 11225

Answers (4)

Doberon
Doberon

Reputation: 648

Other option for use is

<?php

require_once ("tcpdf_barcodes_2d.php");

$code = "Esta es una prueba de codigo FFYL";
$type = "PDF417";

$barcodeobj = new TCPDF2DBarcode($code, $type);

//$barcodeobj->getBarcodePNG();

echo $barcodeobj->getBarcodeHTML(2,2);

?>
<img src="data:image/png;base64,<?php echo base64_encode($barcodeobj->getBarcodePngData(2,2)); ?>">

In this form the image is integrate with the page html and is perfect for send html in email

Upvotes: 2

Jono
Jono

Reputation: 41

@Bimal answered the question but here is an example.

Download the "min" package from the TCPDF sourceforge (http://sourceforge.net/projects/tcpdf/files/tcpdf_min_6_0_025.zip/download)

Unpack the zip file into your WWW folder

Create a new PHP file e.g. barcode.php

include the tcpdf_barcodes_2d.php in your PHP

create a new TCPDF2DBarcode object

generate the PNG barcode using getBarcodePNG()

e.g.:

<?php

require_once ("tcpdf_barcodes_2d.php");

$code = "hello";
$type = "PDF417";

$barcodeobj = new TCPDF2DBarcode($code, $type);

$barcodeobj->getBarcodePNG();

?>

The last line actually generates the image/png data, so you could call this from another PHP script which wraps the output of this in a webpage. e.g.

<html>
<body>
<img src="barcode.php" />
</body>
</html>

The include file does use some other include files so might be worth pruning all the unnecessary PDF generating stuff once you have it working.

Upvotes: 4

user1586379
user1586379

Reputation: 1

Unfortunately, after trying I found that tcpdf do not support Aztec right now, but PDF417 is OK.

Upvotes: 0

Bimal
Bimal

Reputation: 911

Try using TCPDF2DBarCode Class. You would be using setBarcode() method to set a barcode. Next to fetch it in your specific format you can use methods like:

  1. getBarcodePNG()
  2. getBarcodeHTML()
  3. getBarcodeSVG()

Do check out the documentation for more details.

Upvotes: 3

Related Questions