在webbrowser控件中打印谷歌地图 - 不会显示路线

时间:2013-12-11 18:05:37

标签: c# winforms webbrowser-control

使用IE 11,Windows 8.1。

我将以下内容插入到Windows窗体应用程序中:

 var html = "<iframe width=\"425\" height=\"350\" frameborder=\"0\" scrolling=\"no\" marginheight=\"0\" marginwidth=\"0\" " +
               "src=\"https://maps.google.com/maps?f=d&amp;source=s_d&amp;saddr=Oklahoma+City,+OK&amp;daddr=texas&amp;hl=en&amp;" +
               "geocode=FSgxHQIddAQw-imB0vh-VIqthzGdOk_RdBKiMw%3BFVfN5wEdi54L-ilJMoILNnBAhjE83ggYjxzrFg&amp;aq=t&amp;sll=39.632471," +
               "-56.554076&amp;sspn=61.466508,135.263672&amp;mra=ls&amp;ie=UTF8&amp;t=m&amp;z=7&amp;output=embed\">" +
               "</iframe>" +
               "<br /><small><a href=\"https://maps.google.com/maps?f=d&amp;source=embed&amp;saddr=Oklahoma+City,+OK&amp;daddr=texas" +
               "&amp;hl=en&amp;geocode=FSgxHQIddAQw-imB0vh-VIqthzGdOk_RdBKiMw%3BFVfN5wEdi54L-ilJMoILNnBAhjE83ggYjxzrFg&amp;aq=t&amp;" +
               "sll=39.632471,-56.554076&amp;sspn=61.466508,135.263672&amp;mra=ls&amp;ie=UTF8&amp;t=m&amp;z=7\" style=\"color:#0000FF;" +
               "text-align:left\">View Larger Map</a></small>";

        webBrowser1.DocumentText = (html);

现在我想打印这个,但是当我打印预览时它没有显示方向线

 private void button1_Click(object sender, EventArgs e)
    {
        this.webBrowser1.ShowPrintPreviewDialog();           
    }

我尝试了不同的浏览器模拟,但仍无法在Google地图中打印方向线。 IE6 - 11没有运气。

 SetBrowserFeatureControlKey("FEATURE_BROWSER_EMULATION", fileName, GetBrowserEmulationMode());

     public static UInt32 GetBrowserEmulationMode()
    {
        int browserVersion = 7;
        using (var ieKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Internet Explorer",
            RegistryKeyPermissionCheck.ReadSubTree,
            System.Security.AccessControl.RegistryRights.QueryValues))
        {
            var version = ieKey.GetValue("svcVersion");
            if (null == version)
            {
                version = ieKey.GetValue("Version");
                if (null == version)
                    throw new ApplicationException("Microsoft Internet Explorer is required!");
            }
            int.TryParse(version.ToString().Split('.')[0], out browserVersion);
        }

        // Internet Explorer 10. Webpages containing standards-based !DOCTYPE directives are displayed in IE10 Standards mode. Default value for Internet Explorer 10.
        UInt32 mode = 11000;

        switch (browserVersion)
        {
            case 7:
                // Webpages containing standards-based !DOCTYPE directives are displayed in IE7 Standards mode. Default value for applications hosting the WebBrowser Control.
                mode = 7000;
                break;
            case 8:
                // Webpages containing standards-based !DOCTYPE directives are displayed in IE8 mode. Default value for Internet Explorer 8
                mode = 8000;
                break;
            case 9:
                // Internet Explorer 9. Webpages containing standards-based !DOCTYPE directives are displayed in IE9 mode. Default value for Internet Explorer 9.
                mode = 9000;
                break;


            case 10:
                // Internet Explorer 9. Webpages containing standards-based !DOCTYPE directives are displayed in IE9 mode. Default value for Internet Explorer 9.
                mode = 10000;
                break;

            default:
                // use IE10 mode by default
                break;
        }

        return mode;
    }

任何人都可以帮我找出为什么不打印方向线?请记住,直接将此html插入.html文件并使用IE打开,将显示方向线。但他们不打印。

更新

使用IE,您可以将以下内容插入扩展名为html的文档中。

<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0"        marginwidth="0" src="https://maps.google.com/maps?f=d&amp;source=s_d&amp;saddr=Mesa,+AZ+85201&amp;daddr=85258&amp;hl=en&amp;geocode=FXkl_gEduWFV-Sm5aealKggrhzGuOvW7FLWhww%3BFQ8xAAIdIJBU-SmHMd6RyworhzFB0o03Vh1_HQ&amp;aq=t&amp;sll=34.168218,-111.930907&amp;sspn=16.819377,33.815918&amp;mra=ls&amp;ie=UTF8&amp;t=m&amp;ll=33.511629,-111.898842&amp;spn=0.100189,0.145912&amp;z=12&amp;output=embed"></iframe><br /><small><a href="https://maps.google.com/maps?f=d&amp;source=embed&amp;saddr=Mesa,+AZ+85201&amp;daddr=85258&amp;hl=en&amp;geocode=FXkl_gEduWFV-Sm5aealKggrhzGuOvW7FLWhww%3BFQ8xAAIdIJBU-SmHMd6RyworhzFB0o03Vh1_HQ&amp;aq=t&amp;sll=34.168218,-111.930907&amp;sspn=16.819377,33.815918&amp;mra=ls&amp;ie=UTF8&amp;t=m&amp;ll=33.511629,-111.898842&amp;spn=0.100189,0.145912&amp;z=12" style="color:#0000FF;text-align:left">View Larger Map</a></small>

这将在firefox中正确打印所有内容。我已在多台打印机上对此进行了测试。

这在IE中无法正确打印。我尝试过以下方法:

https://support.google.com/maps/answer/21849?hl=en

有关如何让线条出现的任何想法?

1 个答案:

答案 0 :(得分:0)

我不知道您的解决方案是否在任何地方。我不能让我的(XP上的IE8)没有正确显示打印预览。顺便说一句,这是第一次在XP上为我工作但在新操作系统上没有其他人。但是,这里是我经常搞砸的注册表项:

<强> HKLM:

SOFTWARE \ Microsoft \ Internet Explorer \ Main \ FeatureControl \ FEATURE_BROWSER_MODE(10)//您的版本

SOFTWARE \ Microsoft \ Internet Explorer \ Main \ FeatureControl \ FEATURE_BEHAVIORS(0或1)

<强> HKCU:

SOFTWARE \ Microsoft \ Internet Explorer \ Main \ FeatureControl \ FEATURE_USE_LEGACY_JSCRIPT(0或1)

SOFTWARE \ Microsoft \ Internet Explorer \ Main \ FeatureControl \ FEATURE_BROWSER_EMULATION(n000)

此外,请确保在IE Internet Security Zone中设置了这些(或equivelant)选项。

  • 允许编写Microsoft Web浏览器控件的脚本
  • 脚本ActiveX控件标记为可安全编写脚本

Gook运气好!