在 C# 中打印格式化的 HTML 页面 [英] Printing a formatted HTML page in C#

查看:25
本文介绍了在 C# 中打印格式化的 HTML 页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种在 c#(主要是 wpf)中以横向模式打印格式化 html 文件的方法.为了将页面设置设置为横向,打印对话框会很好.我尝试使用 Microsoft 的 html 到 xaml 转换器,但它破坏了格式.我觉得很神奇,没有任何方法或抓取文件并直接发送到打印机.

I am looking for a way to print a formatted html file in landscape mode in c# (primarily wpf). Print dialog would be nice in order to set the page setting to landscape. I tried using Microsoft's html to xaml converter and it destroyed the formatting. I find it quite amazing that there is no method or grabbing a file and sending directly to a printer.

任何想法将不胜感激.

推荐答案

 WebBrowser myWebBrowser = new WebBrowser();
        private void Form1_Load(object sender, EventArgs e)
        {
            myWebBrowser.DocumentCompleted += myWebBrowser_DocumentCompleted;
            myWebBrowser.DocumentText  =System .IO.File .ReadAllText ( @"C:a.htm");
        }

        private void myWebBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            myWebBrowser.Print();
        }

这篇关于在 C# 中打印格式化的 HTML 页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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