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

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

问题描述

我正在尝试从Winform应用程序中的Web浏览器控件进行打印。问题是将字母设置为默认纸张尺寸,但是我需要 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天全站免登陆