Пример #1
0
        public void BrowserPrint()
        {
            var browser = ((GeckoWebBrowser)_pdfViewerControl);

            using (AutoJSContext context = new AutoJSContext(browser.Window)) {
                nsIDOMWindow       domWindow = browser.Window.DomWindow;
                nsIWebBrowserPrint print     = Xpcom.QueryInterface <nsIWebBrowserPrint> (domWindow);

                try {
                    if (PrintProgress != null)
                    {
                        // Send event to disable print, simple, outside cover and inside buttons
                        // while printing
                        PrintProgress.Invoke(this, new PdfPrintProgressEventArgs(true));
                    }
                    _printing = true;
                    print.Print(null, this);
                } catch (COMException e) {
                    if (PrintProgress != null)
                    {
                        PrintProgress.Invoke(this, new PdfPrintProgressEventArgs(false));
                    }
                    //NS_ERROR_ABORT means user cancelled the printing, not really an error.
                    if (e.ErrorCode != GeckoError.NS_ERROR_ABORT)
                    {
                        throw;
                    }
                }
                finally {
                    Marshal.ReleaseComObject(print);
                }
            }
        }
Пример #2
0
 public void OnStateChange(nsIWebProgress aWebProgress, nsIRequest aRequest, uint aStateFlags, int aStatus)
 {
     if (_printing && ((aStateFlags & STATE_STOP) != 0))
     {
         _printing = false;
         if (PrintProgress != null)
         {
             PrintProgress.Invoke(this, new PdfPrintProgressEventArgs(false));
         }
     }
 }