kylemacfarlane / zplgrf

Python utilities for converting to and from ZPL, GRF, PDF, and images
GNU General Public License v3.0
52 stars 11 forks source link

`from_zpl` discards my ZPL #9

Closed mehov closed 1 year ago

mehov commented 1 year ago

Hi

Thank you for sharing the library!

I'm trying to load the following sample ZPL code from https://labelary.com/service.html#data-extraction:

^XA
^FT50,50^A0,50^FDField 1^FS
^FT50,150^A0,50^FDField 2^FS
^XZ
^XA
^FT50,50^A0,50^FDField 3^FS
^FT50,150^A0,50^FDField 4^FS
^XZ

I have it in a text file and then (following an example from https://pypi.org/project/zplgrf/) I run:

with open('label.zpl', 'r') as zpl:
    print(zpl.read())
    grfs = GRF.from_zpl(zpl.read())
    print(grfs)
for i, grf in enumerate(grfs):
    print(i)
    grf.to_image().save('output-%s.png' % i, 'PNG')

The source ZPL code is echoed to me, confirming the file contents are correct. But then I get just [] and that's it.

I looked at the from_zpl source (where GRF loads the ZPL code) and I can see it checks if every line .startswith('~DGR:') and discards those that don't. Apparently, my sample ZPL code got discarded.

Is this on purpose? Should I prepent the '~DGR:' to every line? Or did I misunderstand what the script does completely?

I'm looking to convert ZPL to PNG and your sample code labelled as Extract all GRFs from ZPL and save them as PNGs looked promising.

kylemacfarlane commented 1 year ago

You're misunderstanding the library. It's not a ZPL renderer like Labelary, it simply extract .GRF graphics (~DGR command) from ZPL but it's real utility is in the opposite direction: PDF -> ZPL.

I never found another ZPL renderer as complete as Labelary but it's been years since I checked. I wouldn't want to use Labelary for anything containing customer data as they're too opaque about who they are and their data protection and privacy policies.

If you only want to extract text from ZPL files like in your link to Labelary then you don't need any of this stuff since ZPL is a very simple plain text format.

mehov commented 1 year ago

If you only want to extract text from ZPL files

No no, I need to convert a ZPL code into anything that can be embedded into a webpage. Sorry for the confusion.

I wouldn't want to use Labelary for anything containing customer data as they're too opaque about who they are and their data protection and privacy policies.

1000% and exactly why I keep searching for a working self-hosted option. Also because we need this for a 'mission-critical' process, and Labelary offers no promises, no nothing. I asked them for a quote on their offline engine though.

mehov commented 1 year ago

Thanks anyway! 🙂

kylemacfarlane commented 1 year ago

I've been down that path before and others have emailed me asking the same question. Unless something major has changed then I think unless you build something from scratch (there are a few very limited open source implementations) you're probably out of luck.

I think the official Zebra software has a ZPL preview (renderer) feature and some Zebra printers might have one built into their web interface but integrating either will be messy unreliable hacks.

If you're dealing with shipping labels from the usual big names then in my experience their APIs all have multiple label types and they can give you PDF, HTML, etc as well. Those formats are much easier to work with using open source tools.