Exemple #1
0
        private int PrintAndMagEncode(ZebraCardPrinter zebraCardPrinter, MultiJobControlViewModel jobViewModel)
        {
            using (ZebraGraphics graphics = new ZebraCardGraphics(zebraCardPrinter)) {
                List <GraphicsInfo> graphicsInfoList = new List <GraphicsInfo>();

                if (jobViewModel.HasValidFrontSide)
                {
                    foreach (GraphicsInfo graphicsInfo in CreateGraphicsInfo(graphics, jobViewModel.FrontSideGraphicFilenames, CardSide.Front))
                    {
                        graphicsInfoList.Add(graphicsInfo);
                    }
                }

                if (jobViewModel.HasValidBackSide)
                {
                    foreach (GraphicsInfo graphicsInfo in CreateGraphicsInfo(graphics, jobViewModel.BackSideGraphicFilenames, CardSide.Back))
                    {
                        graphicsInfoList.Add(graphicsInfo);
                    }
                }

                int jobId;
                if (jobViewModel.HasValidMagEncodeJob)
                {
                    jobId = zebraCardPrinter.PrintAndMagEncode(jobViewModel.SelectedQuantity, graphicsInfoList, jobViewModel.Track1Data, jobViewModel.Track2Data, jobViewModel.Track3Data);
                }
                else
                {
                    jobId = zebraCardPrinter.Print(jobViewModel.SelectedQuantity, graphicsInfoList);
                }
                return(jobId);
            }
        }
 public void Add(ZebraCardGraphics zebraCardGraphics)
 {
     using (Font printFont = new Font(Font, FontSize, FontType))
     {
         zebraCardGraphics.DrawText(Text, printFont, Color.FromArgb(FontColourARGB), (int)Math.Round(X), (int)Math.Round(Y));
     }
 }
        private List <GraphicsInfo> CreateGraphicsInfo(ZebraCardGraphics graphics, Dictionary <PrintType, string> imageInfo, CardSide side)
        {
            List <GraphicsInfo> graphicsInfoList = new List <GraphicsInfo>();

            foreach (PrintType type in imageInfo.Keys)
            {
                graphics.Initialize(0, 0, OrientationType.Landscape, type, -1);

                if (type == PrintType.Overlay && imageInfo[type] == null)
                {
                    GraphicsInfo graphicsInfo = new GraphicsInfo {
                        Side        = side,
                        PrintType   = type,
                        GraphicType = GraphicType.NA
                    };
                    graphicsInfoList.Add(graphicsInfo);
                }
                else
                {
                    byte[] imageData = File.ReadAllBytes(imageInfo[type]);
                    graphics.DrawImage(imageData, 0, 0, 0, 0, RotationType.RotateNoneFlipNone);
                    graphicsInfoList.Add(BuildGraphicsInfo(graphics.CreateImage(), side, type));
                }

                graphics.Clear();
            }

            return(graphicsInfoList);
        }
Exemple #4
0
        public GraphicsInfo CreateBackGraphics(ZebraCardPrinter zebraCardPrinter, ZebraCardPrintDetails printDetails)
        {
            using (ZebraCardGraphics graphics = new ZebraCardGraphics(zebraCardPrinter))
            {
                int?fillColour = null;
                graphics.Initialize(0, 0, OrientationType.Landscape, PrintType.MonoK, fillColour);

                // Loop through back text, if any
                if (printDetails.BackPanelText != null & printDetails.BackPanelText.Length > 0)
                {
                    foreach (var text in printDetails.BackPanelZebraText)
                    {
                        text.Add(graphics);
                    }
                }

                // Loop through back images, if any
                if (printDetails.BackPanelImages != null & printDetails.BackPanelImages.Length > 0)
                {
                    foreach (var image in printDetails.BackPanelZebraImages)
                    {
                        image.Add(graphics);
                    }
                }

                ZebraCardImageI zebraCardImage = graphics.CreateImage();
                return(AddImage(CardSide.Back, PrintType.MonoK, 0, 0, -1, zebraCardImage));
            }
        }
        private List <GraphicsInfo> DrawGraphics(ZebraCardPrinter zebraCardPrinter, DataTable data)
        {
            // Generate image data
            ZebraCardImageI zebraCardImage = null;

            //byte[] fontFields = System.Text.Encoding.ASCII.GetBytes("Arial");

            List <GraphicsInfo> graphicsData = new List <GraphicsInfo>();

            using (ZebraGraphics graphics = new ZebraCardGraphics(zebraCardPrinter))
            {
                if (rdoAmbasCaras.Checked)
                {
                    // Front side color
                    zebraCardImage    = DrawCarnetFront(graphics, PrintType.Color, data);
                    pictureBox1.Image = ByteToImage(zebraCardImage.ImageData);

                    //zebraCardImage = DrawImage(graphics, PrintType.Color, imageData, 0, 0, 450, 150);
                    //graphics.DrawImage(imageData, 0, 450, 150, 0, RotationType.RotateNoneFlipXY);
                    //zebraCardImage = graphics.CreateImage();
                    graphicsData.Add(AddImage(CardSide.Front, PrintType.Color, 0, 0, -1, zebraCardImage));
                    graphics.Clear();
                    //// Front side full overlay
                    graphicsData.Add(AddImage(CardSide.Front, PrintType.Overlay, 0, 0, 1, null));

                    // Back side mono
                    zebraCardImage    = null;
                    zebraCardImage    = DrawCarnetBack(graphics, PrintType.MonoK, data);
                    pictureBox2.Image = ByteToImage(zebraCardImage.ImageData);
                    //zebraCardImage = DrawImage(graphics, PrintType.Color, imageData, 0, 0, 450, 150);
                    //graphics.DrawImage(imageData, 0, 450, 150, 0, RotationType.RotateNoneFlipXY);
                    //zebraCardImage = graphics.CreateImage();
                    graphicsData.Add(AddImage(CardSide.Back, PrintType.MonoK, 0, 0, -1, zebraCardImage));
                    graphics.Clear();
                    //// Back side full overlay
                    graphicsData.Add(AddImage(CardSide.Back, PrintType.Overlay, 0, 0, 1, null));
                }

                if (rdoFrontal.Checked)
                {
                    // Front side color
                    zebraCardImage    = DrawCarnetFront(graphics, PrintType.Color, data);
                    pictureBox1.Image = ByteToImage(zebraCardImage.ImageData);

                    //zebraCardImage = DrawImage(graphics, PrintType.Color, imageData, 0, 0, 450, 150);
                    //graphics.DrawImage(imageData, 0, 450, 150, 0, RotationType.RotateNoneFlipXY);
                    //zebraCardImage = graphics.CreateImage();
                    graphicsData.Add(AddImage(CardSide.Front, PrintType.Color, 0, 0, -1, zebraCardImage));
                    graphics.Clear();
                    //// Front side full overlay
                    graphicsData.Add(AddImage(CardSide.Front, PrintType.Overlay, 0, 0, 1, null));
                }

                if (rdoReverso.Checked)
                {
                    // Back side mono
                    zebraCardImage    = null;
                    zebraCardImage    = DrawCarnetBack(graphics, PrintType.MonoK, data);
                    pictureBox2.Image = ByteToImage(zebraCardImage.ImageData);
                    //zebraCardImage = DrawImage(graphics, PrintType.Color, imageData, 0, 0, 450, 150);
                    //graphics.DrawImage(imageData, 0, 450, 150, 0, RotationType.RotateNoneFlipXY);
                    //zebraCardImage = graphics.CreateImage();
                    graphicsData.Add(AddImage(CardSide.Back, PrintType.MonoK, 0, 0, -1, zebraCardImage));
                    graphics.Clear();
                    //// Back side full overlay
                    graphicsData.Add(AddImage(CardSide.Back, PrintType.Overlay, 0, 0, 1, null));
                }
            }

            return(graphicsData);
        }
Exemple #6
0
        private async void ConvertButton_Click(object sender, RoutedEventArgs e)
        {
            JobStatusControl.ClearLog();

            await Task.Run(() => {
                try {
                    using (ZebraGraphics graphics = new ZebraCardGraphics(null)) {
                        graphics.PrinterModel = viewModel.SelectedPrinterModelInfo.PrinterModel;

                        if (!Path.IsPathRooted(viewModel.OriginalGraphicFilename))
                        {
                            throw new ArgumentException("Original graphic filename must be an absolute path");
                        }

                        System.Drawing.Image image = ImageHelper.CreateImageFromFile(viewModel.OriginalGraphicFilename);
                        byte[] imageData           = ImageHelper.ConvertImage(image);

                        int width;  // Width of final output image
                        int height; // Height of final output image

                        switch (viewModel.SelectedDimensionOption)
                        {
                        case DimensionOption.Crop:
                            int croppedWidth  = ConstrainWidth(viewModel.Width, viewModel.SelectedPrinterModelInfo.MaxWidth);
                            int croppedHeight = ConstrainHeight(viewModel.Height, viewModel.SelectedPrinterModelInfo.MaxHeight);
                            imageData         = CropImage(graphics, imageData, croppedWidth, croppedHeight);

                            width  = croppedWidth;
                            height = croppedHeight;
                            break;

                        case DimensionOption.Resize:
                            width  = ConstrainWidth(viewModel.Width, viewModel.SelectedPrinterModelInfo.MaxWidth);
                            height = ConstrainHeight(viewModel.Height, viewModel.SelectedPrinterModelInfo.MaxHeight);

                            JobStatusControl.UpdateLog($"Resizing image to {width}x{height}...");
                            break;

                        case DimensionOption.Original:
                        default:
                            width  = ConstrainWidth(image.Width, viewModel.SelectedPrinterModelInfo.MaxWidth);
                            height = ConstrainHeight(image.Height, viewModel.SelectedPrinterModelInfo.MaxHeight);

                            JobStatusControl.UpdateLog("Keeping current image dimensions unless they exceed the maximum model-specific width and height...");
                            break;
                        }

                        GraphicsFormat graphicsFormat = viewModel.SelectedGraphicsFormat;
                        MonochromeConversion monochromeConversionType = viewModel.SelectedGraphicsFormat.GetMonochromeConversion();
                        PrintType printType             = viewModel.SelectedGraphicsFormat.GetPrintType();
                        OrientationType orientationType = OrientationType.Landscape;

                        JobStatusControl.UpdateLog($"Setting orientation to {orientationType}...");

                        graphics.Initialize(width, height, orientationType, printType, System.Drawing.Color.White);
                        graphics.DrawImage(imageData, 0, 0, width, height, RotationType.RotateNoneFlipNone);
                        ApplyMonochromeConversion(graphics, printType, monochromeConversionType);

                        JobStatusControl.UpdateLog($"Writing graphic file to path {viewModel.ConvertedGraphicFilename}...");

                        WriteToFile(viewModel.ConvertedGraphicFilename, graphics.CreateImage().ImageData);

                        JobStatusControl.UpdateLog("Finished converting graphic");
                    }
                } catch (Exception exception) {
                    string errorMessage = $"Error converting graphic: {exception.Message}";
                    JobStatusControl.UpdateLog(errorMessage);
                    MessageBoxHelper.ShowError(errorMessage);
                }
            });
        }
Exemple #7
0
        private async void PrintButton_Click(object sender, RoutedEventArgs e)
        {
            ZebraCardGraphics graphics = null;
            int?       jobId           = null;
            CardSource?cardSource      = null;

            JobStatusControl.ClearLog();
            await printerManager.PerformAction("Sending print job to printer...", (zebraCardPrinter, connection) => {
                if (printerManager.IsPrinterReady(zebraCardPrinter, JobStatusControl))
                {
                    graphics = new ZebraCardGraphics(zebraCardPrinter);

                    List <GraphicsInfo> graphicsData = new List <GraphicsInfo>();

                    if (viewModel.PrintFrontSide)
                    {
                        byte[] frontSideGraphicData = ImageHelper.ConvertImage(ImageHelper.CreateImageFromFile(viewModel.FrontSideGraphicFilename));
                        graphics.Initialize(0, 0, OrientationType.Landscape, viewModel.FrontSidePrintType, System.Drawing.Color.White);
                        graphics.DrawImage(frontSideGraphicData, 0, 0, 0, 0, RotationType.RotateNoneFlipNone);
                        graphicsData.Add(BuildGraphicsInfo(graphics.CreateImage(), CardSide.Front, viewModel.FrontSidePrintType));
                        graphics.Clear();
                    }

                    if (viewModel.PrintFrontSideOverlay)
                    {
                        if (viewModel.FrontSideOverlayGraphicFilename != null)
                        {
                            byte[] frontSideOverlayGraphicData = ImageHelper.ConvertImage(ImageHelper.CreateImageFromFile(viewModel.FrontSideOverlayGraphicFilename));
                            graphics.Initialize(0, 0, OrientationType.Landscape, PrintType.Overlay, System.Drawing.Color.White);
                            graphics.DrawImage(frontSideOverlayGraphicData, 0, 0, 0, 0, RotationType.RotateNoneFlipNone);
                            graphicsData.Add(BuildGraphicsInfo(graphics.CreateImage(), CardSide.Front, PrintType.Overlay));
                            graphics.Clear();
                        }
                        else
                        {
                            graphicsData.Add(BuildGraphicsInfo(null, CardSide.Front, PrintType.Overlay));
                            graphics.Clear();
                        }
                    }

                    if (viewModel.PrintBackSide)
                    {
                        byte[] backSideGraphicData = ImageHelper.ConvertImage(ImageHelper.CreateImageFromFile(viewModel.BackSideGraphicFilename));
                        graphics.Initialize(0, 0, OrientationType.Landscape, PrintType.MonoK, System.Drawing.Color.White);
                        graphics.DrawImage(backSideGraphicData, 0, 0, 0, 0, RotationType.RotateNoneFlipNone);
                        graphicsData.Add(BuildGraphicsInfo(graphics.CreateImage(), CardSide.Back, PrintType.MonoK));
                        graphics.Clear();
                    }

                    cardSource = (CardSource)Enum.Parse(typeof(CardSource), zebraCardPrinter.GetJobSettingValue(ZebraCardJobSettingNames.CARD_SOURCE));

                    jobId = zebraCardPrinter.Print(viewModel.Quantity, graphicsData);
                }
            }, (exception) => {
                string errorMessage = $"Error printing card: {exception.Message}";
                MessageBoxHelper.ShowError(errorMessage);
                JobStatusControl.UpdateLog(errorMessage);
            }, () => {
                if (graphics != null)
                {
                    graphics.Close();
                }
            });

            if (jobId.HasValue && cardSource.HasValue)
            {
                await JobStatusControl.StartPolling(printerManager.Printer, new JobInfo(jobId.Value, cardSource.Value));
            }
        }
 public void Add(ZebraCardGraphics zebraCardGraphics)
 {
     zebraCardGraphics.DrawImage(ImageData, (int)Math.Round(X), (int)Math.Round(Y), (int)Math.Round(Width), (int)Math.Round(Height), RotationType.RotateNoneFlipNone);
 }