【问题标题】:print automatically html file with powershell使用powershell自动打印html文件
【发布时间】:2022-02-03 16:50:37
【问题描述】:

我想使用 powershell 将 html 文件打印到默认打印机。所以假设我有文件 c:\test.html 和文本:

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

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

提前谢谢你。

【问题讨论】:

  • 我假设您对打印呈现的输出而不是 html 源代码感兴趣。

标签: html powershell printing


【解决方案1】:
get-content c:\test.html  | out-printer

打印到默认打印机。

编辑:

如果您需要打印呈现的 htlm 页面:

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

在 cmets 之后编辑:

我可以在 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()

【讨论】:

  • 谢谢克里斯蒂安!几乎完美。我看到我一直在运行 IE,我应该运行“关闭”命令吗?我尝试了 $ie.Quit() 和 $ie.Close() 但没有运气。有什么想法吗?
  • 要将 IE 会话设置为 $ie,您必须调用 $ie.quit()。这不会关闭其他打开的 IE 会话。您可以再次尝试关闭所有其他 IE 会话吗?
  • 如果我退出它不会打印。试过这个:“While ($ie.Busy) { Start-Sleep -Milliseconds 400 } $ie.Quit()”但它不打印。
  • 进行了 5 秒的硬编码睡眠,它可以工作。需要在主线程中等待或类似的东西。
  • 很高兴它有帮助!查看msdn上的OLECMDID、OLECMDEXECOPT,是ExecWB成员的值!
猜你喜欢
  • 1970-01-01
  • 2021-04-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-09
  • 1970-01-01
  • 2010-09-19
  • 1970-01-01
相关资源
最近更新 更多