简体   繁体   English

在vb.net Windows应用程序中打印HTML页面

[英]Print html page in vb.net windows application

I have a simple html page with place holders in it, when the user fill some info i replace these info in the html page and then print this page, my question is how to print an html page with its embedded format? 我有一个带有占位符的简单html页面,当用户填写一些信息时,我将这些信息替换为html页面中的内容,然后打印此页面,我的问题是如何打印具有嵌入式格式的html页面? Thanks in advance. 提前致谢。

One of your best options would be to put a WebBrowser control on your form. 最好的选择之一是将WebBrowser控件放在窗体上。 It can be hidden if you want. 如果需要,可以将其隐藏。 After saving the StreamWriter 保存StreamWriter之后

        strWriter = New IO.StreamWriter(Application.StartupPath & filename & ".html")
        strWriter.Write(docStuff)
        strWriter.Close()

Then just reload the file into the WebBrowser, and tell it to Print. 然后,只需将文件重新加载到WebBrowser中,并告诉它进行打印即可。 Fairly simple. 很简单。 If you want to get away from the WebBrowser control, then you are going to have to use System.Diagnostics.Process. 如果要摆脱WebBrowser控件,则必须使用System.Diagnostics.Process。 For example, the following line will open the html file in your default Browser. 例如,以下行将在您的默认浏览器中打开html文件。 You are able to add arguments to this statement to get it to print, but you would have to experiment to see what argument you need to get it to autoprint. 您可以在该语句中添加参数以使其打印,但是您将不得不尝试查看将其自动打印所需的参数。

System.Diagnostics.Process.Start(Application.StartupPath & fileName & ".html")

An even easier option is to use ProcessStartInfo. 一个更简单的选择是使用ProcessStartInfo。 You need to Import System.Diagnostics to do this... 您需要导入System.Diagnostics来执行此操作...

    Dim proStart As New ProcessStartInfo
    proStart.FileName = filepathAndName
    proStart.Verb = "print"
    Process.Start(proStart)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM