Need help to throw exception or raise alarm from Printjob if the desired source tray not selected

Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF PrintManager for .NET (v4)  /  Need help to throw exception or raise alarm from Printjob if the desired source tray not selected

DynamicPDF PrintManager for .NET (v4) Forum

HI Team,
can i ask how to raise alarm or raise failed print job event if the print job is not having  desired paper source tray select. i have created below source code  and i realize if i am not setting any paper source tray option, API is using "Automatically select" as the paperSource Tray.

        private void PrintCO(PrintType printType) {
            try {
                if (null == this.printerConfiguration) {
                String tempFile = Path.GetTempFileName();
                byte[] pdfContent = null;
                switch (printType) {
                    case PrintType.ORIGINAL:
                        pdfContent = System.Convert.FromBase64String(coDoc.orignal);

                    case PrintType.COPY:
                        pdfContent = System.Convert.FromBase64String(coDoc.copy);
                File.WriteAllBytes(tempFile, pdfContent);
                PrintJob printJob = new PrintJob(this.printerConfiguration.Name, tempFile);
                printJob.DocumentName = "Letter Portrait";
                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];

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

                    case "PrePrintedWithLogo":
                        if (0 != this.printerConfiguration.PPWithLogoTray) printJob.PrintOptions.PaperSource = printJob.Printer.PaperSources[this.printerConfiguration.PPWithLogoTray];
                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;
                        //at this point in printing i want to raise an alarm if the printJob.PrintOptions.PaperSource is "Automatically Select"
            } catch (Exception ex) {
                throw ex;
Posted by a ceTe Software moderator

Yes, you can throw an exception if PrintJob is not set with paper source other than Auto. You will need to check for the paper source set for the PrintJob dynamically and raise an exception. Below is the code sample.

            PrintJob printJob = new PrintJob("Printer name", @"PDF file path");
            PaperSource paperSourceObj=printJob.PrintOptions.PaperSource;
            if (paperSourceObj.Name.Equals("Automatically Select"))
                throw new Exception("Paper Source is set to Auto");

ceTe Software Support Team

All times are US Eastern Standard time. The time now is 2:43 AM.