none
c# webBrowser调用打印功能时的疑惑 RRS feed

  • 问题

  • 当打印时不会打印背景图片,需要先在IE浏览器里的页面设置上勾选打印背景和图像才可以,但我不想这样,我想要不管是否勾选都打印出背景图片,请问这个在代码中如何实现,谢谢…
    2013年11月7日 9:34

答案

  • Hi,

    You can refer this code.

    SHDocVw.InternetExplorer ie = new SHDocVw.InternetExplorerClass(); 
    SHDocVw.IWebBrowserApp wb = (SHDocVw.IWebBrowserApp) ie; 
    wb.Visible = false;//if u want background printing 
    object noValue = System.Reflection.Missing.Value; 
    object noValue1 = System.Reflection.Missing.Value; 
    ie.Navigate("about:blank", ref noValue, ref noValue, ref noValue, ref noValue); 
    mshtml.IHTMLDocument2 htmlDoc2 = ie.Document as mshtml.IHTMLDocument2; 
    
    // Update the document. 
    htmlDoc2.clear(); 
    htmlDoc2.writeln("<font face=\"Arial\" size=2>Web browser demo. Visit <a href=\"http://www.ryanfarley.com/">http://www.ryanfarley.com/\" target=_blank>ryanfarley.com</a> for more.</font><br><br><a href=\"http://www.ryanfarley.com/">http://www.ryanfarley.com/\" border=0><img src=\"http://ryanfarley.com/Skins/RyanFarleyBlue2/Images/RyanFarley-Title_bg.jpg\" border=0></a>"); 
    
    ie.ExecWB( SHDocVw.OLECMDID.OLECMDID_PRINT,SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER,ref noValue,ref noValue1); 

    For more inforamtion, you can refer here

    http://ryanfarley.com/blog/archive/2004/12/23/1330.aspx

    In addition, please refer the similar thread

    http://stackoverflow.com/questions/48278/how-to-print-css-applied-background-images-with-webbrowser-control

    Hope it can help you.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2013年11月8日 7:37
    版主

全部回复

  • Hi,

    You can refer this code.

    SHDocVw.InternetExplorer ie = new SHDocVw.InternetExplorerClass(); 
    SHDocVw.IWebBrowserApp wb = (SHDocVw.IWebBrowserApp) ie; 
    wb.Visible = false;//if u want background printing 
    object noValue = System.Reflection.Missing.Value; 
    object noValue1 = System.Reflection.Missing.Value; 
    ie.Navigate("about:blank", ref noValue, ref noValue, ref noValue, ref noValue); 
    mshtml.IHTMLDocument2 htmlDoc2 = ie.Document as mshtml.IHTMLDocument2; 
    
    // Update the document. 
    htmlDoc2.clear(); 
    htmlDoc2.writeln("<font face=\"Arial\" size=2>Web browser demo. Visit <a href=\"http://www.ryanfarley.com/">http://www.ryanfarley.com/\" target=_blank>ryanfarley.com</a> for more.</font><br><br><a href=\"http://www.ryanfarley.com/">http://www.ryanfarley.com/\" border=0><img src=\"http://ryanfarley.com/Skins/RyanFarleyBlue2/Images/RyanFarley-Title_bg.jpg\" border=0></a>"); 
    
    ie.ExecWB( SHDocVw.OLECMDID.OLECMDID_PRINT,SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER,ref noValue,ref noValue1); 

    For more inforamtion, you can refer here

    http://ryanfarley.com/blog/archive/2004/12/23/1330.aspx

    In addition, please refer the similar thread

    http://stackoverflow.com/questions/48278/how-to-print-css-applied-background-images-with-webbrowser-control

    Hope it can help you.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2013年11月8日 7:37
    版主

  •    
       u想要的背景
      
           
    
    / /更新文档。htmlDoc2 清除(); htmlDoc2 writeln是“<font face=\"Arial\" size=2> Web浏览器演示。访问的<a href = \”http://www.ryanfarley.com /“ > HTTP / / www.ryanfarley.com/ \“的目标= _blank> ryanfarley.com </ a>的为多。</ FONT> - <A HREF = \”http://www / ryanfarley.com“> http://www.ryanfarley.com/ \”边界= 0> <IMG SRC = \“http://ryanfarley.com/Skins/RyanFarleyBlue2/Images/RyanFarley-Title_bg.jpg \”边界= 0> </ A>“);
    
    ie.ExecWB( SHDocVw.OLECMDID.OLECMDID_PRINT,SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER,ref noValue,ref noValue1); 

    对于更多inforamtion,你可以参考这里

    http://ryanfarley.com/blog/archive/2004/12/23/1330.aspx

    此外,请参阅相似主题

    http://stackoverflow.com/questions/48278/how-to-print-css-applied-background-images-with-webbrowser-control

    希望它可以帮助你。


    我们正在努力,以更好地了解客户的意见,社会支持的经验,所以如果你有时间,你在这次采访中项目的参与将不胜感激。感谢帮助社区论坛一个伟大的地方。
    点击这里参与调查。

    您好,我将代码放到程序里测试了下,但执行SHDocVw.InternetExplorer ie = new SHDocVw.InternetExplorerClass();的时候就会提示错误:检索 COM 类工厂中 CLSID 为 {0002DF01-0000-0000-C000-000000000046} 的组件时失败,原因是出现以下错误: 80070002。 请问这个是什么原因,该如何解决?谢谢…
    2013年11月8日 7:47