Converting .pdf to .zpl
Asked Answered
M

1

7

I need to convert .pdf -file to .zpl -label file for printing with zebra printers, but is this even possible?

The PDF comes in as a base64 encoded string, and somehow I need to output that as a .zpl -file.

I use PHP in my project, and I prefer the method in PHP, but basically any programming language is fine, as long as it gets the job done.

I was thinking about converting the PDF to image(which seems to be possible by quick googling), and then from image(PNG, JPG, etc.) to ZPL(which also seems to be ok by quick googling), but does anyone have any knowledge about this kind of operation or any insights before I start to do this? I'm on a tight schedule here, and I cannot afford any fruitless work.

Update 4.8.2016

I went the other way and created the ZPL from the scratch because it keeps our service faster than doing some conversions. So I don't have any more info on this than what the google already offers, if someone comes wondering about this same thing. PS. ZPL isn't that hard of a language. ;)

Mcfarland answered 26/11, 2015 at 9:5 Comment(8)
My experience with Zebra printers is extremely dated, but considering that PDF is much more (feature) rich than ZPL, it may be best to render the image and send that image to the printer. You would render to the final size/resolution. The image format is preferably PNG, because with JPEG, you will get artefacts, which will show on the Zebra output. So, rendering the PDF as image and sending that image to the Zebra is definitely a way to go, IMHO.Setula
I took this question to have a chat with my former client who is solution provider around Zebra printers. He actually suggests to use the Zebra printer driver, and to send the PDF through it (as opposed to noodle around with ZPL) IF the document is static; for dynamic images, you will have to use ZPL.Setula
@MaxWyss Thank you for contributing your time for this problem. Appreciated. I've heard from our client that printing pdf with zebra printers might not be a good idea when mass printing stuff. We don't have access to the printers nor the drivers, and it was the clients wish to have the printable content as zpl. We are just an interface between two companies, and we're trying to provide the best possible solutions to the client, and having the content in zpl-format is one way to accomplish this.Mcfarland
Is the pdf->png->zpl the only way to go? And is our client right about the pdf being a pain in the butt when mass printing stuff?Mcfarland
PDF is a very powerful format, and thus requiring quite a bit of "dumbing down" for the Zebra printers. But it really depends on what actually gets printed. Is it a PDF background with variable data? Is it a picture? It all depends…Setula
If you have to go the ZPL way, I think (based on my conversation with my former client) the PDF --> image --> ZPL is the most promising approach to the problem.Setula
Alrighty then! Thanks for the insights on this. I'll see what I'll be able to cook up. :)Mcfarland
If you own a Zebra printer of the current generation, there's now an Link-OS app/firmware called PDF direct that enables you to directly print PDFs on those printers. This eliminates the need to convert PDF to ZPL using some middleware.Jeanninejeans
L
4

I had the some problem to solve: take a PDF file, convert it into ZPL code somehow and print it using a Zebra printer.

Thanks to stackoverflow and the ZPL Programming Guide, I learned about embedding bitmaps with the Graphic Field command (^GF).

Basically, you have to do these steps:

  1. Render a PDF file as a bitmap
  2. Make it monochrome
  3. Convert the bitmap into ASCII hexadecimal (as defined by ZPL)
  4. Compress the ASCII hexadecimal (otherwise our printers struggled with megabytes of bitmap data)
  5. Put the data into this code template ^XA^GFA{some parameters and tons of bitmap data}^XZ

Our services were running on ASP.NET so I wrote a C# library to do just that. It wraps the native calls to Google's PDFium for rendering and returns a string with valid ZPL code for printing.

You could convert base64 encoded PDF files like that:

public static string GetZplCode(string pdfBase64, int page = 0, int dpi = 203)
{
    return PDFtoZPL.Conversion.ConvertPdfPage(pdfBase64, page: page, dpi: dpi);
}

I hope this nuget package will prevent others from spending weeks in searching on how to make this ^GF command work.

Lemay answered 10/10, 2021 at 16:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.