首页 > Web开发 > 详细

GeckoWebBrowser 实现网页打印 html打印 去掉页眉页脚 页头页尾

时间:2019-09-07 15:38:04      阅读:320      评论:0      收藏:0      [点我收藏+]
管理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);  
            }  

 

GeckoWebBrowser 实现网页打印 html打印 去掉页眉页脚 页头页尾

原文:https://www.cnblogs.com/tolingsoft/p/11480508.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!