Made a CLI script to print Wikipedia articles:




wget $SRC

mv index* $HTML

html2ps $HTML > $PS

lpr -P pr1444 $PS

It works in the respect that if you write ./print Shane_Mosley this article is printed.

But, compared to using Firefox --- navigate to the site, and print from the menus --- the printed result is inferior: much less compact layout (especially tables), no pictures, and cannot handle "unusual" characters.

So, my question: Is Firefox "monolithic" or is it actually composed of modular tools, that I can replicate? Or could I use Firefox as a server, that I can feed commands (like go there and print)?

If no: are there ways to use my tools in a better way, or are there other tools that would enhance the result?


As you've discovered, this method is suboptimal at best. In addition to the HTML you'll need at a minimum all images and CSS. You may also need all of the Javascript. And then there's the whole deal of rendering this mess.

But for you there is good news in the form of a Command Line Printing extension you can install in Firefox.


firefox -print http://www.example.com/index.html

There are more examples on the extension documentation page.

  • Wow, that's great stuff! – Emanuel Berg Jul 19 '12 at 12:47

I suggest you to grep the $HTML var and find any <img src=.. element and then replace every src attribute with the full image path like https://en.wikipedia.org/wiki/File:Uncle_Tupelo.jpg. By defaut, the server pages technology keeps the image source to the servers relative path like in this case <img src="File:Uncle Tupelo.jpg">. Most of these values are derived from CSS. This will solve the image problem in your print outs, however other CSS element details might still be missing.

An alternative to wget would be to use a quick Perl script.

  • Do you mean I should get the picture paths that way, download them individually and perhaps iterate a list to print them as a sort of appendix at the end of the document? – Emanuel Berg Jul 16 '12 at 21:56
  • Yes, that is the most feasible way to get the pictures using wget i guess. More importantly if the <img src=..> points to a relative path (which is the case with almost all websites) then you have to tell the <img> element exactly where the image resides in the server (like https://www.somesite.com/images/image001.png) and not just the relative path (like /images/image001.png). – Ann Jawn Jul 16 '12 at 23:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.