Exemplo n.º 1
0
        private void printButton_Click(object sender, EventArgs e)
        {
            PrinterSettings ps = new PrinterSettings {
                PrinterName = labelPrinter
            };
            LabelTemplate labelTemplate = labelComboBox.SelectedItem as LabelTemplate;
            double        labelWidth    = labelTemplate.StockWidth;
            double        labelHeight   = labelTemplate.StockHeight;

            ps.Width      = (int)(203 * labelHeight);
            ps.Length     = (int)(203 * labelWidth);
            ps.Darkness   = printDarkness;
            ps.PrintSpeed = printSpeed;

            List <byte> page = new List <byte>();

            page.AddRange(ZPLCommands.ClearPrinter(ps));
            Bitmap bmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);

            labelRenderer.DrawLabel(labelTemplate, bmp, true, GetLabelParameters());
            page.AddRange(ZPLCommands.GraphicStore(bmp, 'R', "img"));
            page.AddRange(ZPLCommands.GraphicWrite(0, 0, "img", 'R'));
            page.AddRange(ZPLCommands.PrintBuffer((int)copiesUpDown.Value));
            new SpoolPrinter(ps).Print(page.ToArray());
        }
Exemplo n.º 2
0
        public void PrintLabel(string label, string printerName, LabelModel model)
        {
            if (string.IsNullOrEmpty(printerName))
            {
                throw new Exception("Nenhuma impressora selecionada.");
            }

            var page            = new List <byte>();
            var printerSettings = GetPrinterSettings(printerName, model);

            var barCode = new Barcode
            {
                Type           = BarcodeType.CODE128_AUTO,
                BarWidthNarrow = 3
            };

            page.AddRange(ZPLCommands.ClearPrinter(printerSettings));
            page.AddRange(ZPLCommands.BarCodeWrite(printerSettings.AlignLeft, printerSettings.AlignTop, 100, ElementDrawRotation.NO_ROTATION, barCode, true, label));

            Print(page, printerSettings);
        }