This topic is locked
[SOLVED]

 How can address labels be printed?

12/23/2020 6:57:45 AM
PHPRunner General questions
A
alfonso authorDevClub member

How can address labels be printed? I don't want to export or use Word but see if it can be done directly from PHPRunner. I have enterprise version

I
Ivan van Oosterhout 12/23/2020

Here is some code how to print to a zebra printer. Maybe it helps you.
Knowledge:

I make a zpl code tekst file and place it on the server (printheader/). Then with copy command i copy the text file to the zebra printer.
$y=1;
$i=1;

$data = $button->getCurrentRecord();

$som1 = str_pad($data["id"],7,0,STR_PAD_LEFT);

$idvalue = "ITH".$som1 ;

$som2 = str_pad($data["PlanID"],7,0,STR_PAD_LEFT);

$idfwb = "FWB".$som2 ;
$myFile = ("printheader/".$idvalue.".txt");

$fh = fopen($myFile, 'w') or die("can't open file");

$stringData = "^XA^PRC^LH040,0^FS\n\r";

fwrite($fh, $stringData);

//Donker afdrukken

$stringData = "^MD0\n";

fwrite($fh, $stringData);

$stringData = "^MNY\n\r";

fwrite($fh, $stringData);

$stringData = "^FO620,430^A0R,80,60^FD".$idvalue."^FS\n\r";

fwrite($fh, $stringData);

$stringData = "^FO470,160^A0R,130,150^FD".$data['zending_soort']."^FS\n\r";

fwrite($fh, $stringData);

$stringData = "^FO460,170^A0R,25^FDDATUM: ".$data['datum']."^FS\n\r";

fwrite($fh, $stringData);

$stringData = "^FO460,610^A0R,25^FDSHUTTLE: ".$data['Shuttle']."^FS\n\r";

fwrite($fh, $stringData);

$stringData = "^FO420,170^A0R,25^FDDOCK LOCATION: ".$data['docklocatie']."^FS\n\r";

fwrite($fh, $stringData);

$stringData = "^FO420,610^A0R,25^FDSITE: ".$data['locatiedetails']."^FS\n\r";

fwrite($fh, $stringData);

$stringData = "^FO380,170^A0R,25^FDFWB NO: ".$idfwb."^FS\n\r";

fwrite($fh, $stringData);

$stringData = "^FO380,610^A0R,25^FDSHIPMENT INFO: ".$data['Zendinginfo']."^FS\n\r";

fwrite($fh, $stringData);

$stringData = "^FO340,170^A0R,25^FDCUSTOMER REF: ".$data['ref_afzender']."^FS\n\r";

fwrite($fh, $stringData);

$stringData = "^FO340,610^A0R,25^FDSHIPMENT REF: ".$data['RefShipment']."^FS\n\r";

fwrite($fh, $stringData);

$stringData = "^FO300,610^A0R,25^FDSCANSESSIE: ".$data['Scansessie']."^FS\n\r";

fwrite($fh, $stringData);

$stringData = "^FO270,170^A0R,50^FD".$data['nietgeteld']."^FS\n\r";

fwrite($fh, $stringData);

$stringData = "^FO220,170^A0R,30^FDSENDER: ".$data['afzender']."^FS\n\r";

fwrite($fh, $stringData);

$stringData = "^FO160,170^A0R,50^FDCUSTOMER:^FS\n\r";

fwrite($fh, $stringData);

$stringData = "^FO120,170^A0R,45^FD".$data['Customer']." - ".$data['deb_naam']."^FS\n\r";

fwrite($fh, $stringData);

$stringData = "^FO70,170^A0R,45^FDPAL^FS\n\r";

fwrite($fh, $stringData);

$stringData = "^FO0,170^A0R,60^FD".$data['pal']."^FS\n\r";

fwrite($fh, $stringData);

$stringData = "^FO70,500^A0R,45^FDCTN^FS\n\r";

fwrite($fh, $stringData);

$stringData = "^FO0,500^A0R,60^FD".$data['crts']."^FS\n\r";

fwrite($fh, $stringData);

$stringData = "^FO70,900^A0R,45^FDGOH^FS\n\r";

fwrite($fh, $stringData);

$stringData = "^FO0,900^A0R,60^FD".$data['pcs']."^FS\n\r";

fwrite($fh, $stringData);

$stringData = "^FO0,1080^A0N,20^FDStickers Printed : ".$y."^FS\n\r";

fwrite($fh, $stringData);

$stringData = "^FO0,1100^A0N,20^FDSticker Printed on : ".now()." by ".$_SESSION["UserID"]."^FS\n\r";

fwrite($fh, $stringData);

$stringData = "^FO20,20\n";

fwrite($fh, $stringData);

$stringData = "^B3o,R,100,Y\n";

fwrite($fh, $stringData);

$stringData = "^FD".$data["id"]."^FS\n";

fwrite($fh, $stringData);

$stringData = "^XZ\n";

fwrite($fh, $stringData);

fclose($fh);
$num = 0;
while ( $num < $y )
{
exec ("lpr -l -h -H" .$_SESSION["printserver"]." -P" .$_SESSION["ZebraPrinter"]." printheader/".$idvalue.".txt");

$num++;
}

S
salus1DevClub member 12/23/2020

If you print from this type of PHPRunner-generated site it will produce Dymo LabelWriter labels.
https://customdataservices.net/qr_codeslabelssignatures1_list.php

Admin 12/23/2020

You can just print the printer-friendly page. Maybe choose vertical or columns mode, select 2 or 3 records per row, modify the way the single record looks according to your needs.

A
alfonso authorDevClub member 12/24/2020

Good ideas. I'll try. Thanks

mbintex 12/24/2020

I have started programming the needed dd-code for PDFmake.js with custom buttons on my own. There you can for example define the paper size of dymo labels your own and decide for the content. In the server event part you fetch the data, in the client after part you build the pdfmake-Code.
See docs of PDFMake for more: https://pdfmake.github.io/docs/0.1/

A
AlphaBase 12/24/2020



In the server event part you fetch the data, in the client after part you build the pdfmake-Code.



It would be great if you could post a simple example of what you are doing - i.e. both the server-side & client-side code. I'm sure many would appreciate it.

mbintex 12/25/2020

This is example of server side:



$i=0;
while($data = $button->getNextSelectedRecord())

{

$i=$i+1;
if ($i>1){

$neueseite=", pageBreak: 'before'";

}
//Schriftgroesse

$result["schriftgroesse"]=10;
//Etikett
$anschrift=trim(preg_replace('/\s\s+/', '\n', $data["Anschrift"]));

$anschrift="{text: '".$anschrift."',style: 'anschrift'".$neueseite."},";
//Zusammenbau
$etikett=$etikett.$anschrift;
//Ende der Schleife

}
$result["etikett"]="[{stack: [".$etikett."]}]";


It goes through the selected records in list page and creates PDFmake text-blocks for each data row. That is passed with $result to client side.


var dd={
background: [

{



}],
header: {
},
footer: {



},
content: [
],
styles: {


},

defaultStyle: {

fontSize: result['schriftgroesse'],

columnGap: 20,

margin:[0,0,0,0]

},

// a string or { width: number, height: number } Dymo 89*28

pageSize: { width: 252, height: 79 },
// by default we use portrait, you can change it to landscape if you wish

pageOrientation: 'landscape',
// [left, top, right, bottom] or [horizontal, vertical] or just a number for equal margins

pageMargins: [ 10,10,10,10 ],
pageBreakBefore: function(currentNode, followingNodesOnPage, nodesOnNextPage, previousNodesOnPage) {

return currentNode.headlineLevel === 1 && followingNodesOnPage.length ===0;}
};
var string=result['etikett'];

eval('var etikett='+string);

dd.content.push(etikett);
pdfMake.createPdf( dd ).download("Etikett.pdf");


On client side I first define an rather empty document and fill that array with my result from server side.
Important for labels is the page size definition width and height. width: 252, height: 79 ist Dymo 8,9cm * 2,8cm

A
AlphaBase 12/25/2020

Cool. Thanks
Where do you put this - in button code or which events?

mbintex 12/27/2020

custom buttons