Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

print automatically html file with powershell

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.

like image 953
Artur Carvalho Avatar asked Dec 02 '25 16:12

Artur Carvalho


1 Answers

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()
like image 157
CB. Avatar answered Dec 05 '25 07:12

CB.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!