Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting .pdf to .zpl

Tags:

php

pdf

zpl

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

like image 945
GotBatteries Avatar asked Nov 26 '15 09:11

GotBatteries


People also ask

How do I convert a PDF to PES?

Upload the PDF file you want to convert. Select your PDF file in the file explorer window, and click Open. Click the drop-down menu next to "convert to." You can find this button at the bottom of the page. It will open a list of all the file types you can convert your PDF to.

Can I print a PDF to a Zebra printer?

If you have a printer with Link-OS you can purchase and install PDF Direct from Zebra on the printer firmware. You can then send a pdf directly to the printer. We do this by connecting to port 9100 and sending the PDF.

Can you convert PDF markdown?

Save PDF as Markdown in Python Read PDF file from the local drive, then simply save it as Markdown, specifying the required file format by MD extension. For both PDF reading and MD writing you can use fully qualified filenames. The output MD content and formatting will be identical to the original PDF document.


1 Answers

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.

like image 74
David Sungaila Avatar answered Oct 01 '22 21:10

David Sungaila