예제 #1
0
        /// <summary>
        /// PDF保存開始処理
        /// </summary>
        private void StartMakingPdf()
        {
            nsIWebBrowserPrint      print       = Xpcom.QueryInterface <nsIWebBrowserPrint>(gecko.Window.DomWindow);
            nsIPrintSettingsService prtService  = Xpcom.GetService <nsIPrintSettingsService>("@mozilla.org/gfx/printsettings-service;1");
            nsIPrintSettings        prtSettings = prtService.GetNewPrintSettingsAttribute();

            prtSettings.SetToFileNameAttribute(tempPdf);        // 保存PDFファイル名
            prtSettings.SetPrintSilentAttribute(true);          // サイレントモード
            prtSettings.SetShowPrintProgressAttribute(false);   // 印刷進捗非表示

            prtSettings.SetPaperHeightAttribute(297.0 * ipm);   // 高さ設定 A4
            prtSettings.SetPaperWidthAttribute(210.0 * ipm);    // 幅設定  A4

            prtSettings.SetMarginTopAttribute(5.08 / mpi);      // 上余白設定
            prtSettings.SetMarginBottomAttribute(5.18 / mpi);   // 下余白
            prtSettings.SetMarginLeftAttribute(5.08 / mpi);     // 左余白
            prtSettings.SetMarginRightAttribute(5.1 / mpi);     // 右余白

            prtSettings.SetHeaderStrLeftAttribute("");          // ヘッダー 左
            prtSettings.SetHeaderStrCenterAttribute("");        // ヘッダー 中
            prtSettings.SetHeaderStrRightAttribute("");         // ヘッダー 右
            prtSettings.SetFooterStrLeftAttribute("");          // フッター 左
            prtSettings.SetFooterStrCenterAttribute("");        // フッター 中
            prtSettings.SetFooterStrRightAttribute("");         // フッター 右
            prtSettings.SetDownloadFontsAttribute(false);

            prtSettings.SetPrintBGColorsAttribute(true);
            prtSettings.SetPrintBGImagesAttribute(true);

            prtSettings.SetOrientationAttribute(nsIPrintSettingsConsts.kPortraitOrientation);   // 用紙向き
            prtSettings.SetOutputFormatAttribute(nsIPrintSettingsConsts.kOutputFormatPDF);      // 保存フォーマット PDF

            print.Print(prtSettings, this);
            finishedTimer.Enabled = true;
        }
예제 #2
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);
                }
            }
        }
예제 #3
0
        private void StartMakingPdf()
        {
            _print = Xpcom.QueryInterface <nsIWebBrowserPrint>(_browser.Window.DomWindow);

            var service       = Xpcom.GetService <nsIPrintSettingsService>("@mozilla.org/gfx/printsettings-service;1");
            var printSettings = service.GetNewPrintSettingsAttribute();

            printSettings.SetToFileNameAttribute(_pathToTempPdf);
            printSettings.SetPrintToFileAttribute(true);
            printSettings.SetPrintSilentAttribute(true);             //don't show a printer settings dialog
            printSettings.SetShowPrintProgressAttribute(false);

            if (_conversionOrder.PageHeightInMillimeters > 0)
            {
                printSettings.SetPaperHeightAttribute(_conversionOrder.PageHeightInMillimeters);
                printSettings.SetPaperWidthAttribute(_conversionOrder.PageWidthInMillimeters);
                printSettings.SetPaperSizeUnitAttribute(1);                 //0=in, >0 = mm
            }
            else
            {
                //doesn't actually work.  Probably a problem in the geckofx wrapper. Meanwhile we just look it up from our small list
                //printSettings.SetPaperNameAttribute(_conversionOrder.PageSizeName);

                var          size = GetPaperSize(_conversionOrder.PageSizeName);
                const double inchesPerMillimeter = 0.0393701;
                printSettings.SetPaperHeightAttribute(size.HeightInMillimeters * inchesPerMillimeter);
                printSettings.SetPaperWidthAttribute(size.WidthInMillimeters * inchesPerMillimeter);
            }
            //this seems to be in inches, and doesn't have a unit-setter (unlike the paper size ones)
            const double kMillimetersPerInch = 25;             //TODO what is it, exactly?

            printSettings.SetMarginTopAttribute(_conversionOrder.TopMarginInMillimeters / kMillimetersPerInch);
            printSettings.SetMarginBottomAttribute(_conversionOrder.BottomMarginInMillimeters / kMillimetersPerInch);
            printSettings.SetMarginLeftAttribute(_conversionOrder.LeftMarginInMillimeters / kMillimetersPerInch);
            printSettings.SetMarginRightAttribute(_conversionOrder.RightMarginInMillimeters / kMillimetersPerInch);


            printSettings.SetDownloadFontsAttribute(true);             //review: what's this for?
            printSettings.SetOrientationAttribute(_conversionOrder.Landscape ? 1 : 0);
            printSettings.SetHeaderStrCenterAttribute("");
            printSettings.SetHeaderStrLeftAttribute("");
            printSettings.SetHeaderStrRightAttribute("");
            printSettings.SetFooterStrRightAttribute("");
            printSettings.SetFooterStrLeftAttribute("");
            printSettings.SetFooterStrCenterAttribute("");

            printSettings.SetPrintBGColorsAttribute(true);
            printSettings.SetPrintBGImagesAttribute(true);


            //TODO: doesn't seem to do anything. Probably a problem in the geckofx wrapper
            //printSettings.SetScalingAttribute(_conversionOrder.Zoom);

            printSettings.SetOutputFormatAttribute(2);             // 2 == kOutputFormatPDF

            Status = "Making PDF..";

            _print.Print(printSettings, this);
            _checkForPdfFinishedTimer.Enabled = true;
        }
예제 #4
0
        public void Print()
        {
            nsIWebBrowserPrint print = Xpcom.QueryInterface <nsIWebBrowserPrint>(_domWindow.Instance);

            print.Print(null, null);

            Marshal.ReleaseComObject(print);
        }
예제 #5
0
        public void Print()
        {
            nsIWebBrowserPrint print = Xpcom.QueryInterface <nsIWebBrowserPrint>(_domWindow.Instance);

            try
            {
                print.Print(null, null);
            }
            catch (COMException e)
            {
                //NS_ERROR_ABORT means user cancelled the printing, not really an error.
                if (e.ErrorCode != GeckoError.NS_ERROR_ABORT)
                {
                    throw;
                }
            }

            Marshal.ReleaseComObject(print);
        }
        public void ShowPrintDialog(nsIDOMWindow parent, nsIWebBrowserPrint webBrowserPrint, nsIPrintSettings printSettings)
        {
            const int NS_ERROR_ABORT = unchecked ((int)0x80004004);

            using (var dialog = new System.Windows.Forms.PrintDialog())
            {
                dialog.UseEXDialog = true;
                if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    var settings = dialog.PrinterSettings;
                    printSettings.SetPrinterNameAttribute(dialog.PrinterSettings.PrinterName);
                    // Add other settings here ...
                }
                else
                {
                    throw new COMException("Operation aborted", NS_ERROR_ABORT);
                }
            }
        }
예제 #7
0
        public void Print()
        {
            nsIWebBrowserPrint print = Xpcom.QueryInterface <nsIWebBrowserPrint>(this.DomWindow);

            print.Print(null, null);
        }
예제 #8
0
        private void StartMakingPdf()
        {
            nsIWebBrowserPrint print = Xpcom.QueryInterface <nsIWebBrowserPrint>(_browser.Window.DomWindow);

            var service       = Xpcom.GetService <nsIPrintSettingsService>("@mozilla.org/gfx/printsettings-service;1");
            var printSettings = service.GetNewPrintSettingsAttribute();

            printSettings.SetToFileNameAttribute(_pathToTempPdf);
            printSettings.SetPrintToFileAttribute(true);
            printSettings.SetPrintSilentAttribute(true);             //don't show a printer settings dialog
            printSettings.SetShowPrintProgressAttribute(false);

            if (_conversionOrder.PageHeightInMillimeters > 0)
            {
                printSettings.SetPaperHeightAttribute(_conversionOrder.PageHeightInMillimeters);
                printSettings.SetPaperWidthAttribute(_conversionOrder.PageWidthInMillimeters);
                printSettings.SetPaperSizeUnitAttribute(1);                 //0=in, >0 = mm
            }
            else
            {
                //doesn't actually work.  Probably a problem in the geckofx wrapper. Meanwhile we just look it up from our small list
                //printSettings.SetPaperNameAttribute(_conversionOrder.PageSizeName);

                var          size = GetPaperSize(_conversionOrder.PageSizeName);
                const double inchesPerMillimeter = 0.0393701;                   // (or more precisely, 0.0393700787402)
                printSettings.SetPaperHeightAttribute(size.HeightInMillimeters * inchesPerMillimeter);
                printSettings.SetPaperWidthAttribute(size.WidthInMillimeters * inchesPerMillimeter);
            }

            // BL-2346: On Linux the margins were not being set correctly due to the "unwritable margins"
            //          which were defaulting to 0.25 inches.
            printSettings.SetUnwriteableMarginTopAttribute(0d);
            printSettings.SetUnwriteableMarginBottomAttribute(0d);
            printSettings.SetUnwriteableMarginLeftAttribute(0d);
            printSettings.SetUnwriteableMarginRightAttribute(0d);

            //this seems to be in inches, and doesn't have a unit-setter (unlike the paper size ones)
            const double kMillimetersPerInch = 25.4;             // (or more precisely, 25.3999999999726)

            printSettings.SetMarginTopAttribute(_conversionOrder.TopMarginInMillimeters / kMillimetersPerInch);
            printSettings.SetMarginBottomAttribute(_conversionOrder.BottomMarginInMillimeters / kMillimetersPerInch);
            printSettings.SetMarginLeftAttribute(_conversionOrder.LeftMarginInMillimeters / kMillimetersPerInch);
            printSettings.SetMarginRightAttribute(_conversionOrder.RightMarginInMillimeters / kMillimetersPerInch);

            printSettings.SetOrientationAttribute(_conversionOrder.Landscape ? 1 : 0);
            printSettings.SetHeaderStrCenterAttribute("");
            printSettings.SetHeaderStrLeftAttribute("");
            printSettings.SetHeaderStrRightAttribute("");
            printSettings.SetFooterStrRightAttribute("");
            printSettings.SetFooterStrLeftAttribute("");
            printSettings.SetFooterStrCenterAttribute("");

            printSettings.SetPrintBGColorsAttribute(true);
            printSettings.SetPrintBGImagesAttribute(true);

            printSettings.SetShrinkToFitAttribute(false);


            //TODO: doesn't seem to do anything. Probably a problem in the geckofx wrapper
            //printSettings.SetScalingAttribute(_conversionOrder.Zoom);

            printSettings.SetOutputFormatAttribute(2);             // 2 == kOutputFormatPDF

            Status = "Making PDF..";

            print.Print(printSettings, this);
            _checkForPdfFinishedTimer.Enabled = true;
        }
 public void ShowProgress(nsIDOMWindow parent, nsIWebBrowserPrint webBrowserPrint, nsIPrintSettings printSettings, nsIObserver openDialogObserver, bool isForPrinting, ref nsIWebProgressListener webProgressListener, ref nsIPrintProgressParams printProgressParams, ref bool notifyOnOpen)
 {
     throw new NotImplementedException();
 }