M-x htmlfontify-buffer can make an HTML view of any buffer in Emacs. Open the HTML using your browser and print it from there—or use the browser to print the file to a PDF file.


Emacs has a command (browse-url-of-file) to send any html file to the selected web browser.

Adding these two things together you suddenly have a way to get a snapshot of the buffer’s view in your web browser. And - finally - if you can print from your web browser, then this gives a simple way to preview and print (with colors) from Emacs.

I implemented this in hfyview.el. Beside printing a buffer it can print a window or frame. If you want to it can also add a Quick Print entry in the File menu.

Both htmlfontify.el + hfyview.el are part of nXthml, which is part of Emacs.

[question] How does bundling something in with an unrelated package that many people don’t need make it easy? I can find htmlfontify.el as a separate download, but where do I get hfyview.el?

It makes it easy for me …;-) And actually for you since doing it this way I can find time to keep it updated all the time. Please look at the reposity for nXhtml. You will find hfyview.el in the util subdir. (But actually I think it is less trouble to just install nXhtml.)

Note: This was originally written for MS Windows because I could not find an easy way to print there, but it is OS independent. From the beginning this was implemented using htmlize.el and htmlize-view.el. I switched to htmlfontify.el instead because htmlfontify could take care of a bit more cases and because htmlfontify will hopefully also soon be part of Emacs. (Here on EmacsWiki there is an old version for MS Windows called Lisp:w32-winprint.el)

See also

PrintingFromEmacs, CategoryWThirtyTwo, PrintingPackage