Simple Zpl printing not working? - php

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.....

Related

php snmpget physical address returns a value with stripped leading 0's

Does anyone have any experience with mac address values via SNMP get in php where it seems to take off the leading 0's?
I'm not sure if there is an easy way to make sure they don't get stripped when I return a value.
For example
IF-MIB::ifPhysAddress.1 = STRING: 0:80:ea:8c:a:e1
Should give me
00:80:ea:8c:0a:e1
Thanks
Your PHP SNMP client is formatting the returned MIB object value incorrectly.
If you have the source code it is probably a trivial fix.
use -O OUTOPTS
Toggle various defaults controlling output display:
0: print leading 0 for single-digit hex characters
snmpget -v2c -c public IF-MIB::ifPhysAddress.1 -O 0

JSON formatting extra characters

I'm trying to send some JSON with Python through an API. It works, but it adds a bunch of funky characters, and I have no idea why or what they mean.
What I'm doing is converting this 'body' variable:
+++[git checkout hashhashhash]+++
+++[git diff --name-status master]+++
M file.php
1 files changed.
to this:
body = {"body":"{{noformat}}{0}{{noformat}}".format(body)}
When that's done, 'body' becomes this:
{'body': '{noformat}\n+++[git checkout hashashashashash]+++\n+++[git diff --name-status master]+++\n\x1b[?1h\x1b=M file.php\x1b[m\r\n\r\x1b[K\x1b[?1l\x1b>\n1 files changed.\n{noformat}'}
Which would be totally fine, except that this is what's posted after it's sent through the API:
+++[git checkout hashashashashashash]+++
+++[git diff --name-status master]+++
[?1h=M file.php[m
[K[?1l>
1 files changed.
I haven't found out what's going on. What is the deal with the [?1h=M and the [K[?1l>, and how do I make them go away?
I think you'll find those are terminal initialization sequences being sent by git - function-key-mode on and function-key-mode off to be precise.
Try using the --no-pager option when producing your original Git output.

jZebra - Getting started with raw commands

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

Modify PHP_Beautifier in Vim to not strip empty lines

Just finished incorporating PHP_Beautifier into Vim and the fact that it removes whitespace irks me. Apparently it's a bug since 2007. There is a hack to fix this problem, but it leads to other problems. Instead I decided to use a round about method.
First Convert multiple blank lines to a single blank line via the command as suggested here
:g/^\_$\n\_^$/d
Next Convert all blank lines to something unique like so (make sure it does not get changed during beautification)
:%s/^[\ \t]*\n/$x = 'It puts the lotion on the skin';\r/ge
Next Call PHP_Beautifier like so
:% ! php_beautifier --filters "ArrayNested() IndentStyles(style=k&r) NewLines(before=if:switch:foreach:else:T_CLASS,after=T_COMMENT:function)"<CR>
Finally Change all unique lines back to empty lines like so
:%s/$x='It puts the lotion on the skin';//ge
All four work when I tested them independently. I also have the third step mapped to my F8 key like so
map <F8> :% ! php_beautifier --filters "ArrayNested() IndentStyles(style=k&r) NewLines(before=if:switch:foreach:else:T_CLASS,after=T_COMMENT:function)"<CR>
But when I try to string the commands together via the pipe symbol, like so (I padded the pipes with whitespace to better show the different commands)
map <F8> :g/^\_$\n\_^$/d | %s/^[\ \t]*\n/$x = 'It puts the lotion on the skin';\r/ge | % ! php_beautifier --filters "ArrayNested() IndentStyles(style=k&r) NewLines(before=if:switch:foreach:else:T_CLASS,after=T_COMMENT:function)" | %s/$x = 'It puts the lotion on the skin';//ge<CR>
I get the following error
Error detected while processing /home/xxx/.vimrc:
line 105:
E749: empty buffer
E482: Can't create file /tmp/vZ6LPjd/0
Press ENTER or type command to continue
How do I bind these multiple commands to a key, in this case F8.
Thanks to ib's answer, I finally got this to work. If anyone is having this same problem, just copy this script into your .vimrc file
func! ParsePHP()
:exe 'g/^\_$\n\_^$/d'
:%s/^[\ \t]*\n/$x = 'It puts the lotion on the skin';\r/ge
:exe '%!php_beautifier --filters "ArrayNested() IndentStyles(style=k&r)"'
:%s/$x = 'It puts the lotion on the skin';//ge
endfunc
map <F8> :call ParsePHP()<CR>
For some Ex commands, including :global and :!, a bar symbol (|) is
interpreted as a part of a command's argument (see :help :bar for the full
list). To chain two commands, the first of which allows a bar symbol in its
arguments, use the :execute command.
:exe 'g/^\_$\n\_^$/d' |
\ %s/^[\ \t]*\n/$x = 'It puts the lotion on the skin';\r/ge |
\ exe '%!php_beautifier --filters "ArrayNested() IndentStyles(style=k&r) NewLines(before=if:switch:foreach:else:T_CLASS,after=T_COMMENT:function)"' |
\ %s/$x = 'It puts the lotion on the skin';//ge

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