---
title: "GeckoWebBrowser实现自定义打印"
author: "jiasongmao"
date: "2018-12-22T00:26:03Z"
tags: []
categories: ["编程语言"]
slug: "geckowebbrowser"
draft: false
lastmod: "2018-12-22T00:26:03Z"
id: 2435573
url: "https://code.iteye.com/blog/2435573"
---

```
nsIWebBrowserPrint print = Xpcom.QueryInterface<nsIWebBrowserPrint>(geckoWebBrowser.Window.DomWindow);
            var service = Xpcom.GetService<nsIPrintSettingsService>("@mozilla.org/gfx/printsettings-service;1");
            var ps = service.GetNewPrintSettingsAttribute();


            ps.SetTitleAttribute(SystemSetting.GetInstance().SystemName);

            ps.SetEdgeBottomAttribute(0);
            ps.SetEdgeTopAttribute(0);
            ps.SetEdgeLeftAttribute(0);
            ps.SetEdgeRightAttribute(0);

            ps.SetMarginBottomAttribute(0);
            ps.SetMarginTopAttribute(0);
            ps.SetMarginLeftAttribute(0);
            ps.SetMarginRightAttribute(0);


            ps.SetShrinkToFitAttribute(true);
            ps.SetPrintSilentAttribute(true);//是否发声
            ps.SetPrintReversedAttribute(true);

            ps.SetOrientationAttribute(1);//横向打印

            try
            {
                print.Print(ps, new WebProgressListener());
            }
            catch (Exception ex)
            {
                MessageBox.Show("打印失败"+ex.Message);
            }
```