There are several packages for this, including:
ps-print -- Renders a buffer as postscript for printing (standard package)
htmlfontify -- Convert a buffer to html (standard package)
htmlize -- Another package for converting a buffer to html. Even though this is not included in the standard Emacs distribution, it is widely used.
e2ansi -- Renders a buffer ...