jZebra - Getting started with raw commands - php

I've been given the task of converting a web page with a barcode to a one click label print. I've got jZebra up and running, but I have no idea where to get started as far as understanding how to write commands for a printer.
I've Google'd just about everything I can think of regarding this.
Basically, I am trying to understand this code:
applet.append("^XA^CF,0,0,0^PR12^MD30^PW800^PON^CI13\n");
// Draws a line. applet.append("^FO0,147^GB800,4,4^FS\n");
applet.append("^FO0,401^GB800,4,4^FS\n");
applet.append("^FO0,736^GB800,4,4^FS\n");
applet.append("^FO35,92^AdN,0,0^FWN^FH^FD^FS\n");
applet.append("^FO615,156^AdN,0,0^FWN^FH^FD(123) 456-7890^FS\n");
Does anyone have links to or information regarding what these characters / commands like "^FO0,401^GB800,4,4^FS" mean or do?

For zebra you this simple guide will help you.
On this Zebra commands
N
q609
Q203,26
B26,26,0,UA0,2,2,152,B,"777777"
A253,56,0,3,1,1,N,"JHON3:16"
A253,26,0,3,1,1,N,"JESUSLOVESYOU"
A253,86,0,3,1,1,N,"TEST TEST TEST"
A253,116,0,3,1,1,N,"ANOTHER TEST"
A253,146,0,3,1,1,N,"SOME LETTERS"
P1,1
on JZebra
var applet = document.jzebra;
if (applet != null) {
applet.append("N\n");
applet.append("q609\n");
applet.append("Q203,26\n");
applet.append("B26,26,0,UA0,2,2,152,B,\"777777\"\n");
applet.append("A253,56,0,3,1,1,N,\"JHON3:16\"\n");
applet.append("A253,26,0,3,1,1,N,\"JESUSLOVESYOU\"\n");
applet.append("A253,86,0,3,1,1,N,\"TEST TEST TEST\"\n");
applet.append("A253,116,0,3,1,1,N,\"ANOTHER TEST\"\n");
applet.append("A253,146,0,3,1,1,N,\"SOME LETTERS\"\n");
applet.append("P1,1\n");}
Having clear this:
EPL is one command per line. A command starts out with a command identifier, typically a letter, followed by a comma-separated list of parameters specific to that command. You can look up each of these commands in the EPL2 programming documentation. Here’s an English-language version of the commands in the above example.
Sending an initial newline guarantees that any previous borked
command is submitted.
[N] Clear the image buffer. This is an important step and
generally should be the first command in any EPL document;
who knows what state the previous job left the printer in.
[q] Set the label width to 609 dots (3 inch label x 203 dpi
= 609 dots wide).
[Q] Set the label height to 203 dots (1 inch label) with a 26
dot gap between the labels. (The printer will probably auto-
sense, but this doesn't hurt.)
[B] Draw a UPC-A barcode with value "777777" at
x = 26 dots (1/8 in), y = 26 dots (1/8 in) with a narrow bar
width of 2 dots and make it 152 dots (3/4 in) high. (The
origin of the label coordinate system is the top left corner
of the label.)
[A] Draw the text "JESUSLOVESYOU" at
x = 253 dots (3/4 in), y = 26 dots (1/8 in) in
printer font "3", normal horizontal and vertical scaling,
and no fancy white-on-black effect.
All tha A starting lines are similar.
10. [P] Print one copy of one label.

After 9,000 hours in google:
Many card printers (such as Zebra or Eltron manufactured printers)
need special RAW printer commands sent to them in order to perform
certain functions (such as magnetic strip encoding or barcode
printing). These RAW commands are usually sent as text in a
proprietary syntax. This RAW syntax is specified by the printer manufacturer (usually in the form of a developer's manual). Syntax
will vary drastically between printer manufacturers and printer
models.
Emphasis is mine. Probably want to google for a developer's manual.
Source: http://code.google.com/p/jzebra/wiki/OldSummaryDoNotUse

Related

How to print (thermal 58) starting from the top position using TCPDF PHP

I'm trying to create an invoice using php (tcpdf), but the results from the thermal (58 print) format always appear in the middle position.
How to make print from top position ?
Example Code :
<?php
require("fpdf/fpdf.php");
include_once "connectdb.php";
$pdf = new FPDF ('P','mm',array(80,145));
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(60,8,'AmmadMaf POS',1,1,'C');
$pdf->SetFont('Arial','B',8);
$pdf->Cell(60,5,'Block 5 Saadi Town, Karachi',0,1,'C');
$pdf->Cell(60,5,'Contact : +92 3222563301',0,1,'C');
$pdf->Cell(60,5,'E-mail Address : ammadfarooqengr#gmail.com',0,1,'C');
$pdf->Cell(60,5,'fb.com/ammadmaf',0,1,'C');
. bla . .
. bla . .
. bla . .
$pdf->Output();
?>
I'd suggest to use or write a proper ESC/POS driver; for example: https://github.com/klirichek/zj-58
There's even official drivers and mobile SDK: http://www.zjiang.com/en/init.php/service/driver
Together with a PHP library eg. escpos-php, so that one could eventually control the printer.
There's usually a page mode and line mode. Controlling the printer directly with escape sequences gives full control of line feeds, the cutter and the cash drawer. Opening the cash drawer with a key after having entered to amount is not how it's meant to work (which is where this questionable approach would lead). Just render to HTML with any monospaced font for on-screen preview.
Dont try to print unitless PDF to a thermal printer, you will be attempting to send a Page Language to an esc/POS rolling 203 DPI printer that has variable lengths by using a roll cutter. IF you must use PDF ensure the content is matched to the roll width and cut length (harder done than said) # the correct pixel resolution in monochrome and you may still often get castellated aliased graphics.
Your key issue is the page is defined for that printout as 128 inches high (1 full page height = 1 roll length) thus you need a format and driver that is not designed for pages.
For the Zj printers there are Cups system alternate driver at https://github.com/futurelink/cups-thermo-printer or https://github.com/klirichek/zj-58 and the manufacturer supplies a multi windows version XP to 10 driver for use with the printer.
Normally I would recommend using SeaGull BarTender for Windows USB thermal printing but that model is not clearly supported https://www.seagullscientific.com/support/downloads/drivers/
Idealy you should use the printers own variant of esc/POS thermal language as instantly runs text or esc/POS binary through the port direct, not PDF through a much slower system driver with a PDF translation into monochrome escodes/text/bitmap stream for slow spooling.
The printer stream will NOT be a %PDF- it will look at the start somthing like
p #P#B
v0 0 yï¾ûï¾ûï¾ûï
It should contain "open drawer" and "stop rolling at end of print", plus for blade enabled plotters a "cut roll" command. A good esc/POS SDK will include template designers for ensuring the text and graphics are pixel perfect. This Epson template designer can produce an editable XML structure for use with simple web javascript.
You say you still want an answer to the original question and in this case one option is to force the print page to the top of the paper roll page with a custom lower margin ! just beware there is no cut to be seen , so I would expect the whole page to be ejected all over the floor.

PHP: Parse .csv file with line breaks in field value (partly quoted)

There are some questions on this topic already however I did not find a satisfying answer yet. While common .csv reader software (e.g. Libre Office) can read the file without any problems PHP has problems with this.
Sample part of the file:
86010800,class,Table Games,,"(10005183, 10005184, 10005185)"
86011100,class,Toy Vehicles – Non-ride,,"(10005192, 10005190, 10005191, 10005193, 10005194, 10005195, 10005196)"
86011000,class,Toys – Ride-on,,"(10005187, 10005188, 10005441, 10005189)"
86010900,class,Toys/Games Variety Packs,,(10005186)
10001686,brick,Airbrushes (Powered),"Definition:
Includes any products that can be described/observed as a powered
machine that scatters paint using air pressure and which is used for
design illustrations, fine art and delicate fine spray applications. The
machine comprises of a compression or propulsion device to scatter the
paint.Specifically excludes Spray Paint and Aerosols.Excludes Airbrushing Replacement Parts and Accessories such as Airbrush Control Valves and Airbrush Hoses.",()
10001688,brick,Airbrushing Equipment – Replacement Parts/Accessories,Definition: Includes any products that can be described/observed as a replacement part/accessory for airbrushing equipment.Includes products such as Airbrush Control Valves and Airbrush Hoses.Excludes products such as complete Airbrushes.,(20001349)
10001690,brick,Airbrushing Supplies Other,"Definition:
Includes any products that may be described/observed as Airbrushing
Supplies products, where the user of the schema is not able to classify
the products in existing bricks within the schema.Excludes all currently classified Airbrushing Supplies.",()
As you can see column 4 and column 5 are partly quoted as they may contain line breaks, simple values are not quoted.
What I want is a 2-dimensional array where a row is level 1 and the five columns of the row are level 2.
I have tried
fgetcsv()
which fails parsing the multiline fields and
str_getcsv()
which fails parsing in two dimensions both with the correct parameters. How to parse this .csv-file best correctly with PHP?
Hope SplFileObject::fgetcsv() helps you to parse the CSV file. In below-mentioned link the example is already given, so use that and check its get fetched properly or not.
http://php.net/manual/en/splfileobject.fgetcsv.php
Edit: Full code sample
$file = new SplFileObject('../../temp/file.csv');
$ar = array();
while (!$file->eof()) {
array_push($ar,$file->fgetcsv());
}
echo '<pre>';
print_r($ar);
echo '</pre>';
die;

Simple Zpl printing not working?

I have this in test.txt
CT~~CD,~CC^~CT~^XA~TA000~JSN^LT0^MNW^MTT^PON^PMN^LH0,0^JMA^PR6,6~SD15^JUS^LRN^CI0^XZ^XA^MMT^PW508^LL0203^LS0^BY4,3,138^FT48,155^BCN,,Y,N^FD>;12^FS^PQ1,0,1,Y^XZ
and I use the Zpl printer Google chrome add-on
On my mac in terminal I tried (after some ls)
lp -d zpl test.txt
All i get is 26 labels with error messages
ERROR: requested label 0, but there are only 0 labels
I also tried
lp -d zpl test.txt -o position=top-left,ppi=203,landscape
still 26 labels
But I expected something like this (but I have different label dimensions)
Few things I can find in your code.
Firstly
CT~~CD,~CC^~CT~^XA~TA000~JSN^LT0^MNW^MTT^PON^PMN^LH0,0^JMA^PR6,6~SD15^JUS^LRN^CI0^XZ^
This is an invalid label and the XA and XZ are telling the printer that this is one label (you really have two labels above, 2 pairs XA to start and XZ to end). Put just that part in an online zpl viewer and you will see the invalid with the same error. Your data is actually in the second portion of your code. Take out the middle ^XZ and ^XA and leave the first ^XA and ending ^XZ. Your code should work then.
Also FYI you don't need CT~~CD,~CC^~CT~ along with much of other parts of your code. These commands are telling the printer to change the control characters, however you telling them to change them to the default. example CT = change tilde then you put to tilde, and CC = change carot to carot etc.....

Creating a code128 barcode in PHP, using a font instead of rendering it as an image

I need to be able to convert any string into a code128 barcode that can be printed on a PDF.
My idea was to embed a code128 font into the PDF and simply use that font to render the string that I need to show as a barcode, letter for letter.
However, I found out that I also need to calculate a checksum and include the start and stop characters.
Is this not possible using PHP? I have not found any solution anywhere. The only solutions that I could find are for directly rendering the barcode as an image, which does not help in my current situation, since I need to use a font to create the barcode in the PDF.
If you restrict your efforts to 128B, you have access to upper and lower case characters, numbers and most punctuation. It also saves you from having to write code to shift in and out of A and C symbologies. This makes the code to calculate the checksum really trivial.
Code 128B start character has a value of 104. The stop character for all Code 128 variations has a value of 106, but that value does not figure into the chksum calculation. Let's pick the string "Hello" for a real life exercise. You'll want to make sure you have access to the Code 128 table. All the values I will be discussing are out of that table and not ASCII or UTF-8.
The checksum is calculated by adding the multiple of a character’s value by its position in the barcode with the exception of the start code.
While the start code’s position is ‘1’, so is the position of the first character following the start code. So the start code and the first byte of data (‘H’) are both multiplied by the number 1 ((104 × 1) + (40 × 1) = 144).
The following 4 bytes get an incrementally higher multiplier ((69 x 2) + (76 × 3) + (76 × 4) + (79 × 5) = 1065). Summing it all up together (144 + 1065) we get 1209.
You should be able to use the modulus operator (1209 % 103) in PHP to get 76 for the checksum character for the Code 128B string “Hello” (the 103 is a constant, trust me on that). So the final array of codes to map "Hello" into a Code 128 barcode is:
[104 40 69 76 76 79 76 106].
You'll need lookup tables to convert the string character values to Code 128B character values to whatever your barcode font is expecting. But all you need is a loop, an array index, an accumulator for the sum of the factors and a modulus operator against the constant value of 103.
The easisest way to generate a barcode in PHP for PDF is to use a dedicated software library.
AFAIK, the most complete one is currently the tc-lib-barcode (https://github.com/tecnickcom/tc-lib-barcode) that allows you to generate both linear and bidimensional barcodes. The included example should give you a quick start.
The source code is fully PSR-2 compliant and can be easily added to your PHP projects using Composer.
The original code has been ported and refactored from TCPDF and already used in billions of documents.

Converting a PDF to JPG with ImageMagick in PHP Gives Odd Letter Spacing

I am trying to convert a PDF to a JPG with a PHP exec() call, which looks like this:
convert page.pdf -resize 716x716 page.jpg
For some reason, the JPG comes out with janky text, despite the PDF looking just fine in Acrobat and Mac Preview. Here is the original PDF:
http://whit.info/dev/conversion/page.pdf
and here is the janktastic output:
http://whit.info/dev/conversion/page.jpg
The server is a LAMP stack with PHP 5 and ImageMagick 6.2.8.
Can you help this stumped Geek?
Thanks in advance,
Whit
ImageMagick is just going to call out to Ghostscript to convert this PDF to an image. If you run gs on the pdf, you get the same badly-spaced output.
I suspect Ghostscript isn't handling the PDF's embedded TrueType fonts very well. If you could change your output to either embed Type 1 fonts or use a "core" PostScript font, you'd get better results.
I suspect its an encoding/widths issue. Both are a tad off, though I can't put my finger on why.
Here are some suspects:
First
The text stream is defined in UTF-16 LE. charNULLcharNULL, using the normal string drawing command syntax:
(some text) Tj
There's a way to escape any old character value into a () string. You can also define strings in hex thusly:
<203245> Tj
Neither method are used, just the questionable inline nulls. That could cause an issue in GS if it's trying to work with pointers to char without lengths associated with them.
Second
The widths array is dumb. You can define widths in groups thusly:
[ 32 [450 525 500] 37 [600 250] 40 [0] ]
This defines
32: 450
33: 525
34: 500
37: 600
38: 250
40: 0
These fonts defines their consecutive widths in individual arrays. Not illegal, but definitely wasteful/stupid, and if GS were coded to EXPECT gaps between the arrays, it could induce a bug.
There's also some extremely fishy values in the array. 32 through 126 are defined consecutively, but then it starts jumping all over: ...126 [600] 8364 [500] 8216 [222] 402 [500] 8222 [389]. 8230 [1000] 8224 [444]... and then goes back to being consecutive from 160 to 255.
Just weird.
Third
I'm not even remotely sure, but the CIDToGIDMap stream contains an AWEFUL lot of nulls.
Bottom line
Those fonts are fishy. And I've never heard of "Bellflower Books" or "UFPDF 0.1"
That version number makes me cringe. It should make you cringe too.
Googleing for "UFPDF" I found this note from the author:
Note: I wrote UFPDF as an experiment, not as a finished product. If you have problems using it, don't bug me for support. Patches are welcome though, but I don't have much time to maintain this.
UFPDF is a PHP library that sits on top of FPDF. 0.1. Just run away.

Categories