コード例 #1
0
 public new bool Print(string printer, string url, WebSocketSession session, FilePrintHelper filePrint)
 {
     try
     {
         if (base.useRaw)
         {
             return(base.Print(printer, url, session, filePrint));
         }
         _session   = session;
         _filePrint = filePrint;
         _url       = url;
         PrintDocument printDocument = new PrintDocument();
         printDocument.PrintPage += new PrintPageEventHandler(OnPrintAll);
         if (!String.IsNullOrEmpty(printer))
         {
             printDocument.PrinterSettings.PrinterName = printer;
         }
         printDocument.Print();
         return(true);
     }
     catch (Exception ex)
     {
         filePrint.SendErrorMsg(session, "Print", "Print image error", ex);
         Logger.Error("IMAGEPrinting.print =>", ex);
     }
     return(false);
 }
コード例 #2
0
        public new bool Print(string printer, string url, WebSocketSession session, FilePrintHelper filePrint)
        {
            try
            {
                if (base.useRaw)
                {
                    return(base.Print(printer, url, session, filePrint));
                }
                if (useBrowserPrint)
                {
                    var infoBrowserConsole = new ProcessStartInfo();
                    infoBrowserConsole.Arguments = " \"" + url + "\"   \"" + printer + "\"";
                    //info.Arguments = "printername=\"" + printer + "\"   url=\"" + url + "\"";
                    var pathToBrowserExe = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                    infoBrowserConsole.FileName = Path.Combine(pathToBrowserExe, "BrowserPrint.exe");
                    Logger.Log("Starting browser-print:" + infoBrowserConsole.FileName);
                    using (var p = Process.Start(infoBrowserConsole))
                    {
                        // Wait until it is finished
                        while (!p.HasExited)
                        {
                            System.Threading.Thread.Sleep(10);
                        }
                        // Return the exit code
                        return(p.ExitCode == 0);
                    }

                    return(true);
                }
                // Spawn the code to print the packing slips
                var info = new ProcessStartInfo();
                info.Arguments = margins + " -p \"" + printer + "\" \"" + url + "\"";
                //info.Arguments = "printername=\"" + printer + "\"   url=\"" + url + "\"";
                var pathToExe = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                info.FileName = Path.Combine(pathToExe, "PrintHtml.exe");
                using (var p = Process.Start(info))
                {
                    // Wait until it is finished
                    while (!p.HasExited)
                    {
                        System.Threading.Thread.Sleep(10);
                    }
                    // Return the exit code
                    return(p.ExitCode == 0);
                }
            }
            catch (Exception ex)
            {
                filePrint.SendErrorMsg(session, "Print", "Print html error", ex);
                Logger.Error("HTMLPrinting.print =>", ex);
                return(false);
            }
        }
コード例 #3
0
        public bool Print(string printer, string url, WebSocketSession session, FilePrintHelper filePrint)
        {
            try
            {
                // Create an instance of the Printer
                IPrinter printerRaw = new Printer();

                // Print the file
                printerRaw.PrintRawFile(printer, url, Path.GetFileName(url));

                return(true);
            }
            catch (Exception ex)
            {
                filePrint.SendErrorMsg(session, "Print", "Print raw error", ex);
                Logger.Error("RAWPrinting.print =>", ex);
                return(false);
            }
        }
コード例 #4
0
 public new bool Print(string printer, string url, WebSocketSession session, FilePrintHelper filePrint)
 {
     try
     {
         if (base.useRaw)
         {
             return(base.Print(printer, url, session, filePrint));
         }
         Process.Start(
             Registry.LocalMachine.OpenSubKey(
                 @"SOFTWARE\Microsoft\Windows\CurrentVersion" +
                 @"\App Paths\AcroRd32.exe").GetValue("").ToString(),
             string.Format("/h /t \"{0}\" \"{1}\"", url, printer));
         return(true);
     }
     catch (Exception ex)
     {
         filePrint.SendErrorMsg(session, "Print", "Print pdf error", ex);
         Logger.Error("PDFPrinting.print =>", ex);
         return(false);
     }
 }
コード例 #5
0
        //private Microsoft.Office.Interop.Word.Document doc;
        // where did you get this file name?


        //public bool Print(string printer, string url)
        //{
        //    try
        //    {
        //        doc = word.Documents.Open(url, ReadOnly: true, Visible: false);

        //        object copies = "1";
        //        object pages = "";
        //        object range = Microsoft.Office.Interop.Word.WdPrintOutRange.wdPrintAllDocument;
        //        object items = Microsoft.Office.Interop.Word.WdPrintOutItem.wdPrintDocumentContent;
        //        object pageType = Microsoft.Office.Interop.Word.WdPrintOutPages.wdPrintAllPages;
        //        object oTrue = true;
        //        object oFalse = false;


        //        if (doc != null)
        //        {
        //            doc.Application.ActivePrinter = printer;
        //            doc.PrintOut(ref oTrue, ref oFalse, ref range, ref missing, ref missing, ref missing,
        //                    ref items, ref copies, ref pages, ref pageType, ref oFalse, ref oTrue,
        //                    ref missing, ref oFalse, ref missing, ref missing, ref missing, ref missing);
        //        }

        //        return true;
        //    }
        //    catch (Exception ex)
        //    {
        //        Logger.Error("WORDPrinting.print =>", ex);
        //        return false;
        //    }
        //}



        // should be a singleton instance of wrapper for Word
        // the code below assumes this was set beforehand
        // (e.g. from another helper method)
        //private static Microsoft.Office.Interop.Word._Application _app;

        public new bool Print(string printer, string fileName, WebSocketSession session, FilePrintHelper filePrint)
        {
            try
            {
                if (base.useRaw)
                {
                    return(base.Print(printer, fileName, session, filePrint));
                }
                _session     = session;
                _filePrint   = filePrint;
                word.Visible = false;
                // Sometimes Word fails, so needs to be restarted.
                // Sometimes it's not Word's fault.
                // Either way, having this in a retry-loop is more robust.
                for (int retry = 0; retry < _exceptionLimit; retry++)
                {
                    if (TryOncePrintToSpecificPrinter(fileName, printer, retry))
                    {
                        break;
                    }

                    if (retry == _exceptionLimit - 1) // this was our last chance
                    {
                        // if it didn't have actual exceptions, but was not able to change the printer, we should notify somebody:
                        throw new Exception("Failed to change printer.");
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                filePrint.SendErrorMsg(session, "Print", "Print word error", ex);
                Logger.Error("WORDPrinting.print =>", ex);
                return(false);
            }
        }