Print a Web Page From a Shell Prompt

How do I print a web page from a shell prompt or shell script?

You need to use html2ps command convert HTML to PostScript. . The HTML code can be retrieved from one or more URL:s or local files, specified as parameters on the command line. If no parameter is given, html2ps reads from standard input.

Install html2ps

Type the following command under Debian / Ubuntu Linux to install the package:
# apt-get update && apt-get install html2ps
Turn on EPEL repo under Fedora / RHEL / CentOS Linux and type the following command to install html2ps package:
# yum install html2ps

Get HTML source code

Type the following command:
$ html2ps http://example.com/file.html
$ html2ps http://www.cyberciti.biz/tips/networking-subnet-mask.html

To print a web page, pipe output using lpr or lp command:
$ html2ps http://www.cyberciti.biz/tips/networking-subnet-mask.html | lpr
$ html2ps http://www.cyberciti.biz/tips/networking-subnet-mask.html | lp -d hpdjet

Further readings:

  • man page lp, lpr and html2ps

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 1 comment so far... add one


CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
1 comment… add one
  • Rizwan Abbas May 1, 2016 @ 17:36

    I have been looking for this solution for 4 days and here it is. I implemented and now I can send print requests to print my invoices on network printer.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum