Create PDF label from text

Hello,

For one of our scripts we want to create a small label (76mmx25mm) with a specific text that gets generated.

For this i have a Debian 11 Cups install with a Zebra ZD420 (network) connected to it. This printer is also the default for this server. When i use lpstat -d the output confirms this:

system default destination: GK420_koopjes

So i tested this with echo "test" | lp and i can confirm that the printer prints a label indeed.

The problem however is that this label is not filling the complete label. It only has 1 small text in the corner.

Does anyone know how i can set the text to fill the width of the label and if possible in Bold also?

Hello,

The issue here would be that if you just send plain text to a printer, then the printer will indeed start printing exactly as you describe, from the top left, with no formatting. Normally it's the page description language that determines how a page looks - typically PostScript, PDF or PCL.

Now, I've not heard of Zebra printers before now, but a quick spot of Googling tells me that they don't use PostScript or PCL, but instead use their own dedicated page formatting language, called ZPL. So you would need to write the text to be printed in a ZPL file if you wanted formatting to be included, and you'd then send that ZPL file straight to the printer using a raw device in CUPS. Or that seems to be the gist of it anyway, from what I'm reading.

So, I'd start from there: read up on ZPL, try creating and printing a few simple test files, and hopefully you'll be able to get to the formatting and appearance you want. Hope this helps !

2 Likes

Thank you for the comment but the printer itself does not necessary need ZPL to function. I can also send normal pdf's to the printer if that makes it easier.

In the mean time i will check ZPL out if i can manage to make it work :slight_smile:

Then pass your print file through enscript and ghostscript to create a pdf file.
https://www.gnu.org/software/enscript/
https://www.ghostscript.com/
Roughly:

enscript -f Font@size/pitch -h -p output.ps<input.txt
ps2pdf output.ps output.pdf
5 Likes

Hi,

Ah, if you can send PDFs to the printer and they work as expected in terms of formatting and layout, then that's the way to go, definitely. And using GhostScript, as per @jgt's suggestion, is indeed an excellent way to do that. I've generally always found GhostScript to be very useful when printing from Linux, for all kinds of jobs.

Thank you everyone for the input. I did some fiddling and by sheer accident i found some good zpl guides so i tested with that first as i was checking that anyway.

I have the following labels now:

^XA

^FX Top section with logo, name and address.
^CF0,125
^FO0,60^FWN,2^FB609,1,0,C,0 ^FDK00009999\&^FS
^XZ

and

^PR
^XA

^FO116,20 ^BC,100 ^FD5555581613002^FS

^FO5,170^A0N,25,25^FB609,3,0,C,0^FDMakita CL072DZ draagbare stofzuiger Koopjeshoek\&^FS
^XZ

At first it was only the question if i could get the first one to work but after some more fiddling i found that i could also generate a barcode and with some more fiddling i got it to work. So i actually managed to solve both issues even though the first one was the one i asked help with.

Both labels arent perfect but they suffice for our needs. The only thing i need to do is to either make them a template and put a variable in it which i overwrite or i will create the file each time i am going to call on the script. The second option has my preference so i will continue with that.

btw printing of a ZPL file can be done as follows:

lp -o raw barcode.zpl
3 Likes