Exemplo n.º 1
0
        /**
         * <summary>
         *      Executes the actual currCoPrinting.
         * </summary>
         * <param name="printType">Can be ORIGINAL or COPY</param>
         * <param name="coDoc">Contains all related details of the CO</param>
         */
        private void SendCOToPrinter(PrintType printType, CoDoc coDoc)
        {
            try {
                //If no printerConfiguration object is found.
                if (null == this.printerConfiguration)
                {
                    return;
                }

                //TestPrintJob_Succeeded();
                String tempFile   = Path.GetTempFileName();
                byte[] pdfContent = null;
                switch (printType)
                {
                case PrintType.ORIGINAL:
                    pdfContent = System.Convert.FromBase64String(coDoc.orignal);
                    break;

                case PrintType.COPY:
                    pdfContent = System.Convert.FromBase64String(coDoc.copy);
                    break;
                }

                File.WriteAllBytes(tempFile, pdfContent);
                PrintJob printJob = new PrintJob(this.printerConfiguration.Name, tempFile);
                printJob.DocumentName = "Letter Portrait";

                //If printer is colored
                if (printJob.Printer.Color)
                {
                    printJob.PrintOptions.Color = true;
                }

                printJob.PrintOptions.Copies = 1;
                //?
                PaperSize paperSize = printJob.Printer.PaperSizes.A4;
                if (paperSize != null)
                {
                    printJob.PrintOptions.PaperSize = paperSize;
                }

                printJob.PrintOptions.HorizontalAlign  = HorizontalAlign.Center;
                printJob.PrintOptions.Orientation.Type = OrientationType.Portrait;
                AutoPageScaling scaling = new AutoPageScaling(ScaleTo.PagePrintableArea, true, true);
                printJob.PrintOptions.Scaling = PageScaling.ActualSize;
                printJob.PrintOptions.Scaling = scaling;
                switch (coDoc.coMediaType)
                {
                case "PrePrinted":
                    if (0 != this.printerConfiguration.PinkTray)
                    {
                        printJob.PrintOptions.PaperSource = printJob.Printer.PaperSources[this.printerConfiguration.PinkTray];
                    }
                    break;

                case "A4":
                    if (0 != this.printerConfiguration.WhiteTray)
                    {
                        printJob.PrintOptions.PaperSource = printJob.Printer.PaperSources[this.printerConfiguration.WhiteTray];
                    }
                    break;

                case "PrePrintedWithLogo":
                    if (0 != this.printerConfiguration.PPWithLogoTray)
                    {
                        printJob.PrintOptions.PaperSource = printJob.Printer.PaperSources[this.printerConfiguration.PPWithLogoTray];
                    }
                    break;
                }
                printJob.PrintOptions.PrintAnnotations = false;
                printJob.PrintOptions.Resolution       = printJob.Printer.Resolutions[this.printerConfiguration.Resolution];
                printJob.PrintOptions.VerticalAlign    = VerticalAlign.Top;
                printJob.Succeeded += PrintJob_Succeeded;
                printJob.Failed    += PrintJob_Failed;
                printJob.Updated   += PrintJob_Updated;

                //code to counter the non select print media type. to stop them currCoPrinting from random tray
                if (printJob.PrintOptions.PaperSource.Name == "Automatically Select")
                {
                    throw new Exception("Please select printer tray for media type" + coDoc.coMediaType);
                }

                //TestPrintJob_Succeeded();
                printJob.Print();
            } catch (Exception ex) {
                Console.WriteLine(ex.StackTrace);
                throw ex;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Test print the CO
        /// </summary>
        /// <param name="formType"></param>
        /// <param name="coDoc"></param>
        private void TestPrintCO(WebPrintRestProxy.FormType formType, CoDoc coDoc)
        {
            try {
                if (null == this.printerConfiguration)
                {
                    Alert(SmarteCOPrintControl.Properties.Resources.ERR_CONFIG_INVALID_CONFIG);
                    return;
                }
                if (this.cbPPWithLogo.Checked == true || this.cbPink.Checked == true)
                {
                    offsetText_check();
                }
                String tempFile = Path.GetTempFileName();
                Console.WriteLine("tempFile: " + tempFile);
                byte[] originPDF = System.Convert.FromBase64String(coDoc.orignal);
                File.WriteAllBytes(tempFile, originPDF);
                PrintJob printJob = new PrintJob(this.printerConfiguration.Name, tempFile);
                printJob.DocumentName = "Letter Portrait";
                if (printJob.Printer.Color)
                {
                    printJob.PrintOptions.Color = true;
                }

                printJob.PrintOptions.Copies = 1;
                //settin paper size to A4 #Saurabh
                PaperSize paperSize = printJob.Printer.PaperSizes.A4;
                if (paperSize != null)
                {
                    printJob.PrintOptions.PaperSize = paperSize;
                }

                printJob.PrintOptions.HorizontalAlign  = HorizontalAlign.Center;
                printJob.PrintOptions.Orientation.Type = OrientationType.Portrait;

                AutoPageScaling scaling = new AutoPageScaling(ScaleTo.PagePrintableArea, true, true);
                printJob.PrintOptions.Scaling = PageScaling.ActualSize;
                printJob.PrintOptions.Scaling = scaling;
                switch (formType)
                {
                case WebPrintRestProxy.FormType.PINK_FORM:
                    if (-1 != this.printerConfiguration.PinkTray)
                    {
                        printJob.PrintOptions.PaperSource = printJob.Printer.PaperSources[this.printerConfiguration.PinkTray];
                    }
                    break;

                case WebPrintRestProxy.FormType.WHITE_FORM:
                    if (-1 != this.printerConfiguration.WhiteTray)
                    {
                        printJob.PrintOptions.PaperSource = printJob.Printer.PaperSources[this.printerConfiguration.WhiteTray];
                    }
                    break;
                }
                printJob.PrintOptions.PrintAnnotations = false;
                printJob.PrintOptions.Resolution       = printJob.Printer.Resolutions[this.printerConfiguration.Resolution];
                printJob.PrintOptions.VerticalAlign    = VerticalAlign.Top;
                printJob.Starting  += PrintJob_Starting;
                printJob.Succeeded += PrintJob_Succeeded;
                printJob.Failed    += PrintJob_Failed;
                printJob.Updated   += PrintJob_Updated;
                printJob.Print();
            } catch (Exception ex) {
                LogException(ex);
            }
        }