管理GeckoFx
PM> Install-Package Geckofx45 -Version 45.0.34
GeckoWebBrowser geckoWebBrowser;
public Form1()
{
InitializeComponent();
Xpcom.Initialize("Firefox");
geckoWebBrowser = new GeckoWebBrowser { Dock = DockStyle.Fill };
this.Controls.Add(geckoWebBrowser);
geckoWebBrowser.Navigate("www.baidu.com");
}
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.SetFooterStrCenterAttribute("");
ps.SetFooterStrLeftAttribute("");
ps.SetFooterStrRightAttribute("");
ps.SetHeaderStrCenterAttribute("");
ps.SetHeaderStrLeftAttribute("");
ps.SetHeaderStrRightAttribute("");
ps.SetOrientationAttribute(1);//横向打印
try
{
print.Print(ps, new WebProgressListener());
}
catch (Exception ex)
{
MessageBox.Show("打印失败"+ex.Message);
}
来源:oschina
链接:https://my.oschina.net/u/4341084/blog/3402788