WebBrowser print settings

[亡魂溺海] 提交于 2019-11-26 07:48:39

问题


How ca i change my html document orientation(to Landscape) for printing using WebBrowser control.

var browser = new WebBrowser();
browser.DocumentCompleted += (sender, args) =>
    {
        var ws = sender as WebBrowser;
        //change paper size and orientation
        ws.Print();
    };
browser.Navigate(path);

I need to change paper size format to C5 and orientation to Landscape before printing. How can i do this without any dialogs?


回答1:


To control HTML printing layout beyond @media CSS with WebBrowser (both WinForms and WPF), you would need to implement your own Internet Explorer Print Template. That would provide full control over headers, margins, columns, etc.

Specifically, you're after TemplatePrinter.orientation. It isn't properly documented, but it works. The source of the standard IE print template can be viewed when navigated to res://ieframe.dll/preview.dlg.

Some other relevant resources:

  • Beyond Print Preview: Print Customization for Internet Explorer 5.5
  • Print Preview 2: The Continuing Adventures of Internet Explorer 5.5 Print Customization
  • Print Templates, Part I
  • View templates for HTML source documents
  • Demystifying printing with the Microsoft WebBrowser control and ShowHTMLDialogEx
  • Add support to print & preview HTML in a dialog-based MFC app
  • IDM_PRINT
  • IDM_PRINTPREVIEW
  • MSKB: How to print custom headers and footers for a WebBrowser control in Internet Explorer


来源:https://stackoverflow.com/questions/19098571/webbrowser-print-settings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!