如何从 Web 浏览器控件设置纸张尺寸和边距打印 [英] How to set Paper Size and Margins printing from a web browser control

查看:54
本文介绍了如何从 Web 浏览器控件设置纸张尺寸和边距打印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 winform 应用程序中的 Web 浏览器控件进行打印.问题是它将 letter 设置为默认纸张尺寸,但我需要 A4.它还会自动设置一些边距错误,我可以手动将它们设置为更正设置,但我想以编程方式进行.

I am trying to print from a web browser control in a winform application.The matter is it sets letter as default paper size but I need A4. Also it automatically sets some margins wrong, I can set them to correct settings manually but I want to do it programmatically.

怎么可能?

这是我要打印的代码.

private void metroButton1_Click(object sender, EventArgs e)
    {
        loadprintData();
        // Create a WebBrowser instance. 
        WebBrowser webBrowserForPrinting = new WebBrowser();

        // Add an event handler that prints the document after it loads.
        wa.DocumentCompleted +=
            new WebBrowserDocumentCompletedEventHandler(ShowPrintDocument);
        wa.ShowPrintPreviewDialog();
        reloadpage();

    }
    private void ShowPrintDocument(object sender,WebBrowserDocumentCompletedEventArgs e)
    {
        // Print the document now that it is fully loaded.
        ((WebBrowser)sender).ShowPrintPreviewDialog();

        // Dispose the WebBrowser now that the task is complete. 
        // ((WebBrowser)sender).Dispose();
        reloadpage();
    }
    private void PrintDocument(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
        // Print the document now that it is fully loaded.
        ((WebBrowser)sender).Print();

        // Dispose the WebBrowser now that the task is complete. 
       // ((WebBrowser)sender).Dispose();
    }

推荐答案

好吧,我尝试了很多东西,但最后我发现无法轻松地从代码中对打印机设置进行编程.但我可以通过@jeremy 的回答来做保证金.我发现对于从 WebBrowser 控件进行打印,它使用我们所知道的 Internet Explorer,但一开始它使用的是 Explorer 7,我不得不将其更改为默认的 Explorer 11.然后我看到资源管理器没有自己的打印设置.它使用默认打印机设置.因此,您必须更改默认打印机预览.您将看到预览会以这种方式显示.

Well i have tried so many things but at the end i found that it is not possible to program the printer setting from the code easily. but i could do the margin by the answer of @jeremy. And i found out that For printing from WebBrowser control it uses internet explorer all we know but at the beginning it was using explorer 7 and i had to change it to explorer 11 as default. Then i saw it explorer does not have his own print settings. it uses the default printers settings. So you have to change the Default printers previews.You will see the preview will show that way.

这篇关于如何从 Web 浏览器控件设置纸张尺寸和边距打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆