Print without ZPL?

We have a GX430t to which I would like to print over USB without using ZPL, EPL, etc.

 

Right now, we are using C# to print out rendered svg images (which include barcodes, text, etc.):

 

// userControl is a rendered svg var d = new PrintDialog         {             PrintQueue = _queue,             PrintTicket = _validatedPrintTicket         }; d.PrintVisual(userControl, "Print");

 

It would be really nice if we didn't have to treat the Zebra printer differently than other printers (or with some minimal changes).

Is there a way of making this method work with Zebras?

 

Or maybe there are other workarounds:

Could the image be written to an array and wrapped with ZPL to make it work?

Is there an easy way to convert SVG to something the printer will understand?

Are there other drivers for the Zebra that I am not seeing that would allow us to work with it in a more standard manner?

 

Any help or thoughts are appreciated!

Anonymous (not verified)
Hi Nathan,You should be able

Hi Nathan,

You should be able to use the driver the same as any other print driver.  I do recommend installing the ZebraDesigner drivers.  I have not tested if you can directly print an SVG, but you can convert an svg to a png or any standard singular image format.  This would be the same for any print driver, so if you can do it with a standard printer, it should work with ours.  Hope this makes sense.

The following code should print a png to any printer with a normal driver, including Zebra printers.

        private System.Drawing.Printing.PrintDocument docToPrint = new System.Drawing.Printing.PrintDocument();

        private System.Windows.Forms.PrintDialog printDialog1 = new System.Windows.Forms.PrintDialog();

        private void button1_Click(object sender, EventArgs e)

        {

            try

            {

                docToPrint.PrintPage += document_PrintPage;

                // Set the Document property to the PrintDocument for

                // which the PrintPage Event has been handled. To display the

                // dialog, either this property or the PrinterSettings property

                // must be set

                printDialog1.Document = docToPrint;

                DialogResult result = printDialog1.ShowDialog();

                // If the result is OK then print the document.

                if (result == DialogResult.OK)

                {

                    docToPrint.Print();

                }

            }

            catch (Exception ex)

            {

                MessageBox.Show(ex.Message);

            }

        }

        // The PrintPage event is raised for each page to be printed.

        private void document_PrintPage(object o, PrintPageEventArgs e)

        {

            string filepath = @"C:\My Documents\Pictures\Logo.png";

            System.Drawing.Image img = System.Drawing.Image.FromFile(filepath);

            Point loc = new Point(100, 100);

            e.Graphics.DrawImage(img, loc);

        }

Credits: PrintDialog Class (System.Windows.Forms)  and Print images c#.net - Stack Overflow

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Nathan Barnett
Thanks for the quick reply,

Thanks for the quick reply, Robin! You got me moving in the right direction.

After some mucking around with it yesterday, I got it to work. We are working with WPF, so we were sticking with the recommended (and easiest) way of printing (PrintVisual from my question). It seems that the Zebra driver only supports GDI (?). Because of that you have to use a PrintDocument (not Forms specific) and draw the rendered control to it, which obviously takes some work (hopefully this will be helpful for someone):

var render = new RenderTargetBitmap(width, height, 300, 300, PixelFormats.Pbgra32);
render.Render(userControl);

var encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(render));
var image = GetImage(encoder);

// Setup a print document and specify the printer
var docToPrint = new PrintDocument
                    {
                        PrinterSettings =
                        {
                            PrinterName = printer.FullName
                        }
                    };

docToPrint.PrintPage += (sender, e) =>
                        {
                            e.PageSettings.Margins.Top = _margin.Top;
                            ...

                            e.Graphics.DrawImage(image, new Point(0, 0));
                        };

docToPrint.Print();

private static Image GetImage(BitmapEncoder encoder)

{

    using (Stream fs = new MemoryStream())

    {

        encoder.Save(fs);

        return Image.FromStream(fs);

    }

}

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Anonymous (not verified)
Thanks Nathan, Looks good.GDI

Thanks Nathan, Looks good.

GDI just means the driver supports Windows Graphical interface so you don't have to convert application display images to print control language.  This is exactly what your code is showing.  It's usually compared to PCL and PostScript drivers which are print control languages commonly used in home and office printers.  As our printers don't by default support those languages, we 'only' support GDI in the drivers. 

I do have one warning to others about printing with WPF... don't try to use XPS documents to print.  The rendering library in WPF for XPS documents is very limited and often causes distortions when printing.  You are much better off using the direct Graphics drawing library to print as Nathan has shown.

Vote: 
Vote up!
Vote down!

Points: 0

You voted ‘up’


Log in to post comments