I want to create a label sticker with barcode in PDF. Please give me the suggestion to create this things. Now , I use CI3 and dompdf.
I have tried googling a lot of time, but I am not found the best practice to realized this thing.
I followed your suggestion, Now I have folder in vendor/Piqcer.
I try this into my view_report like this:
<tr>
<td class="solid" colspan="2">
<?= $value->NO_URUT ?>
<?php
$generator = new \Picqer\Barcode\BarcodeGeneratorPNG();
echo '<img src="data:image/png;base64,' . base64_encode($generator->getBarcode($value->NO_URUT, $generator::TYPE_CODE_128)) . '">';
?>
</td>
</tr>
But I got error :
Fatal error: Class 'Picqer\Barcode\BarcodeGeneratorPNG' not found
UPDATE
So, this library is on ci_folder\vendor\picqer\php-barcode-generator
. Now I create an autoload library like this :
class Barcode {
public function generate($id) {
require_once("./vendor/picqer/php-barcode-generator/src/BarcodeGeneratorJPG.php");
$generator = new Picqer\Barcode\BarcodeGeneratorJPG();
echo $generator->getBarcode($id, $generator::TYPE_CODE_128);
}
}
IN my controller :
$this->load->library('dompdfgenerator');
$this->load->library('barcode');
$data = array(
'result' => $result,
'container' => $containers
);
$html = $this->load->view('members/megumi/check_list_per_tanggal/v_laporan_sticker_pilihan', $data, true);
$this->dompdfgenerator->generate($html, "$identity");
Now in view :
<tr>
<td class="solid" colspan="2">
<?= $value->NO_URUT ?>
<?php
echo '<img src="data:image/png;base64,' . base64_encode($this->barcode->generate($value->NO_URUT)) . '">';
?>
</td>
</tr>
It still : Fatal error: Class 'Picqer\Barcode\BarcodeGenerator' not found
Please advise...
Have you tried using libraries, such as PHP Barcode Generator. It will generate a barcode for you and export it as an SVG, PNG or JPG or HTML. You should just insert the resulting barcode to the HTML you wil lbe exporting with DOMPDF.
I think you may get some idea from this answer Integrate barcode reader generate/read with Codeigniter. Also note that the files of BarcodeGenerator are stored in the third_party folder of the application.