使用powershell自动打印html文件

发布于 2024-12-01 15:01:36 字数 220 浏览 2 评论 0原文

我想使用 powershell 将 html 文件打印到默认打印机。假设我有文件 c:\test.html ,其中包含以下文本:

<html>
<p> hello <b>world</b></p>
<html>

如何将 test.html 打印到默认打印机?

先感谢您。

I want to print an html file to the default printer with powershell. So lets say I have the file c:\test.html with the text:

<html>
<p> hello <b>world</b></p>
<html>

How could I print test.html to the default printer?

Thank you in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

活雷疯 2024-12-08 15:01:36
get-content c:\test.html  | out-printer

打印到默认打印机。

编辑:

如果您需要打印渲染的 html 页面:

$ie = new-object -com "InternetExplorer.Application"
$ie.Navigate("c:\test.html")
$ie.ExecWB(6,2)

在注释后编辑:

我可以在 testprint.ps1 文件中运行它:

$ie = new-object -com "InternetExplorer.Application"
$ie.Navigate("c:\test.html")
while ( $ie.busy ) { Start-Sleep -Seconds 3 }
$ie.ExecWB(6,2)
while ( $ie.busy ) { Start-Sleep -Seconds 3 }
$ie.quit()
get-content c:\test.html  | out-printer

Print to default printer.

Edit:

if you need print rendered htlm page:

$ie = new-object -com "InternetExplorer.Application"
$ie.Navigate("c:\test.html")
$ie.ExecWB(6,2)

Edit after comments:

I can run this in a testprint.ps1 file:

$ie = new-object -com "InternetExplorer.Application"
$ie.Navigate("c:\test.html")
while ( $ie.busy ) { Start-Sleep -Seconds 3 }
$ie.ExecWB(6,2)
while ( $ie.busy ) { Start-Sleep -Seconds 3 }
$ie.quit()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文