Reputation:
with help of below code, i successfully displaying tracking_id in pdf , Now i am trying to displaying bar code image....
Its working fine if i use static value . but when i passed column value instead of static value it gave error :
Static : $text = isset($_GET['text']) ? $_GET['text'] : "1234";
Dynamic :
$text = isset($_GET['text']) ? $_GET['text'] : $tracking_id;
Result :
I guess I am passing tracking_id column value not in proper manner :
<?php
$con = mysqli_connect("localhost","root","iJ564645qA9v3J","do_management4");
include('database.php');
$result = mysqli_query($con,"SELECT * FROM orders");
while($row = mysqli_fetch_array($result))
{
$id = $row['id'];
$tracking_id = $row['tracking_id'];
}
$database = new Database();
$result = $database->runQuery("SELECT tracking_id FROM orders where id = '".$_REQUEST['id']."'");
$header = $database->runQuery("SELECT UCASE(`COLUMN_NAME`)
FROM `INFORMATION_SCHEMA`.`COLUMNS`
WHERE `TABLE_SCHEMA`='do_management4'
AND `TABLE_NAME`='orders'
and `COLUMN_NAME` in ('tracking_id')");
require __DIR__ . '/../vendor/autoload.php';
use BarcodeBakery\Barcode\BCGcode11;
// Loading Font
$font = new BCGFontFile(__DIR__ . '/../font/Arial.ttf', 18);
// Don't forget to sanitize user inputs
$text = isset($_GET['text']) ? $_GET['text'] : $tracking_id;
// The arguments are R, G, B for color.
$color_black = new BCGColor(0, 0, 0);
$color_white = new BCGColor(255, 255, 255);
$drawException = null;
try {
$code = new BCGcode11();
$code->setScale(2); // Resolution
$code->setThickness(30); // Thickness
$code->setForegroundColor($color_black); // Color of bars
$code->setBackgroundColor($color_white); // Color of spaces
$code->setFont($font); // Font (or 0)
$code->parse($text); // Text
} catch (Exception $exception) {
$drawException = $exception;
}
$drawing = new BCGDrawing('', $color_white);
if ($drawException) {
$drawing->drawException($drawException);
} else {
$drawing->setBarcode($code);
$drawing->draw();
}
// Header that says it is an image (remove it if you save the barcode to a file)
header('Content-Type: image/png');
header('Content-Disposition: inline; filename="barcode.png"');
// Draw (or save) the image into PNG format.
$drawing->finish(BCGDrawing::IMG_FORMAT_PNG);
?>
Upvotes: 1
Views: 155
Reputation: 209
Use BCGcode39
it allows you to use more characters lik capital letters and some special characters. or keep using BCGcode11
but then you need to remove the unallowed characters.
Upvotes: 0
Reputation: 15257
Considering the documentation BCGcode11
allows only the numbers from 0 to 9 and a hyphen (-)
You either can
Remove the unwanted characters from $tracking_id
which may lead to wrong datas
Use the proper class for the barecode you want.
BCGcode39 allows more characters to build your barecode : Code 39 contains all the capital letters, the numbers from 0 to 9, the following special characters "-.$/+%" and spaces.
Upvotes: 1