Exemple #1
0
         public static bool PrintLabelZpl(string printerName, string zplCommand, string jobName = "label")
         {
             var baseStream = new MemoryStream();
             var tw = new StreamWriter(baseStream, Encoding.UTF8);
             tw.WriteLine(zplCommand);
             tw.Flush();
             baseStream.Position = 0;
 
             var gdiJob = new GdiPrintJob(printerName, GdiPrintJobDataType.Raw, jobName, null);
             gdiJob.WritePage(baseStream);
             gdiJob.CompleteJob();
 
             return true;
         }
    static unsafe void Main(string[] args)
    {
        var baseStream = new MemoryStream();
        var tw         = new StreamWriter(baseStream, Encoding.UTF8);

        using (var bmpSrc = new Bitmap(Image.FromFile(@"label.png")))
        {
            tw.WriteLine(ZplImage.GetGrfStoreCommand("R:LBLRA2.GRF", bmpSrc));
        }
        tw.WriteLine(ZplImage.GetGrfPrintCommand("R:LBLRA2.GRF"));
        tw.WriteLine(ZplImage.GetGrfDeleteCommand("R:LBLRA2.GRF"));
        tw.Flush();
        baseStream.Position = 0;
        var gdipj = new GdiPrintJob("ZEBRA S4M-200dpi ZPL", GdiPrintJobDataType.Raw, "Raw print", null);

        gdipj.WritePage(baseStream);
        gdipj.CompleteJob();
    }
    public static bool PrintLabelBase64Image(string printerName, string base64Image, string jobName = "label")
    {
        try
        {
            var bmpLabel   = Base64ToBitmap(base64Image);
            var baseStream = new MemoryStream();
            var tw         = new StreamWriter(baseStream, Encoding.UTF8);
            tw.WriteLine(GetGrfStoreCommand("R:LBLRA2.GRF", bmpLabel));
            tw.WriteLine(GetGrfPrintCommand("R:LBLRA2.GRF"));
            tw.WriteLine(GetGrfDeleteCommand("R:LBLRA2.GRF"));
            tw.Flush();
            baseStream.Position = 0;

            var gdipj = new GdiPrintJob(printerName, GdiPrintJobDataType.Raw, jobName, null);
            gdipj.WritePage(baseStream);
            gdipj.CompleteJob();

            return(true);
        }
        catch (Exception)
        {
            return(false);
        }
    }