Printing webpage using browser via CLI

browserchromecommand linefirefoxprinting

I want to automate printing. From URL in text file, the webpage is printed. I have tried using wget and the results are very inferior than when printed via browser. Somehow FF and Chromium both manage to convert webpages to "printability" format by redacting sidebars and such. Also, wget fetched webpages have no images. How do I make my prints look readable?

I am thinking of writing dumb macro for mouse and keyboard movements to manually do it using web browser, but CLI is better, less error prone.

There used to be an extension, but it is not maintained anymore and does not install on FF33.

Are there any ways to do it?

Best Answer

Printing via CLI

One method would be to use html2ps.

$ html2ps http://example.com/file.html | lpr

-or-

$ html2ps http://example.com/file.html | lp -d someprinter

Saving to PDF

As an added bonus if you just want to keep it as a PDF file you can use ps2pdf like so:

$ html2ps http://example.com/file.html | ps2pdf - somfile.pdf

References

Related Question