PDF barcode (DadaBik field for TCPDF php function)

TechSupport

New member
Hello,

We are trying to add a barcode representation of a field value in a PDF label produced from a single record detail view. The barcode will be generated using TCPDF's 'write1DBarcode()' function which is installed in the PDF template php file's 'pdf_custom_code_after_addpage($pdf)' function.

Our question is, how do we get the required field value into the 'write1DBarcode()' php function, as in:

$pdf->write1DBarcode( FIELD_NAME/FIELD_VALUE , 'C128', '', '', '', 6, 0.4, $style, 'N');

Regards, TechSupport
 

eugenio

Administrator
Staff member
Hello,
at the moment it is not a feature provided by DaDaBIK: the TCPDF library is used to produce a PDF representation of a record's details page, in DaDaBIK there isn't any "barcode" field type, so if you have the barcode as a picture already you can show it, otherwise you cannot "translate" a value into a barcode automatically through DaDaBIK.

Best,
 

TechSupport

New member
Hi Eugenio,

That is a shame. As TCPDF can generate barcodes from text I assumed it would be a simple matter to pass the value from a DaDaBik field/record to the TCPDF php function via the template php file. By example, the following php template snippet works to provide a barcode of the current DaDaBik user:

function pdf_custom_code_after_addpage($pdf){
$pdf->write1DBarcode($_SESSION['logged_user_infos_ar']["username_user"], 'C128', '', '', '', 6, 0.4, $style, 'N');
$pdf->Cell(0, 0, $_SESSION['logged_user_infos_ar']["username_user"], 0, 1);
}

Regards, TechSupport
 

eugenio

Administrator
Staff member
Hello,
unfortunately it's more complicated: we need to create a new field type, which is quite a thing in itself because DaDaBIK needs to know how to handle this field type in all the different parts of the application, but there is more:

1) we need implement a solution to create barcodes in HTML, not only in PDF

2) DaDaBIK uses a TCPDF function, writehtml(), that does its best to convert an HTML page in PDF: for example HTML IMG tags are automatically converted in PDF images ... this, however, doesn't work for barcodes, there isn't any html "barcode tag" that TCPDF automatically converts in a PDF barcode

Best,
 

taubes

Member
Here is a thought, you can create one temporary file (pdf or any image) that gets generated every time a record is shown and return while custom formatting. I used this before, it is not super fast but works.Just make sure the folder has appropriate writing permissions. Instead of TCPDF I used phpqrcode (http://phpqrcode.sourceforge.net). The principle should work either way.
Also, if you do this on the primary key field you can query anything in that database if needed.

function dadabik_QRCode($value){
include('qrcode/qrlib.php');
QRcode::png($value,'qrcode/temp/QRCode.png');
return "<img src='qrcode/temp/QRCode.png' />";
}

alternatively using this you can link to each record directly

function dadabik_QRCode($value){
include('qrcode/qrlib.php');
QRcode::png("https://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}",'qrcode/temp/QRCode.png');
return "<img src='qrcode/temp/QRCode.png' />";
}

Good luck.
 

eugenio

Administrator
Staff member
That's a smart solution! I don't know phpqrcode so I am not sure how well it works and how well that picture produced is then converted in PDF but for sure it is a good start.

Best,
 
Top