Can I have hyperlinks a different color for printing?

hyperref has the option ocgcolorlinks which does exactly what you want.

From hyperref's README

Experimental option ocgcolorlinks

The idea are colored links, when viewed, but printed without colors.

This new experimental option ocgcolorlinks uses Optional Content Groups, a feature introduced in PDF 1.5.

  • The option must be given for package loading:

      \usepackage[ocgcolorlinks]{hyperref}
    
  • Main disadvantage: Links cannot be broken across lines.

....

Beware of the fact, that, however, "Links cannot be broken across lines" with this option, so, if you need this, you'd better use colorlinks option and print in "black and white".


I use a compile-time switch. That is, I have this in my file header.

\usepackage{etoolbox}
% Are printing a hard copy or not?
\newbool{hardcopybool}
  % set the default by uncommenting one or the other
  % \booltrue{hardcopybool} 
  \boolfalse{hardcopybool}  % the default  
% You can cause hyperlinks to be black by invoking with
%   pdflatex "\def\hardcopy{}\input{book}"
% See http://stackoverflow.com/a/1466610
\ifdefined\hardcopy 
  \booltrue{hardcopybool}
\fi
\ifbool{hardcopybool}{\typeout{!!! PRINTING HARD COPY}}{}

and later I have this as part of my import of hyperref.

  \usepackage[
                colorlinks=true,
                \ifbool{hardcopybool}{linkcolor=black,citecolor=black,filecolor=black,urlcolor=black}{linkcolor=darkcolor,citecolor=darkcolor,filecolor=darkcolor,urlcolor=darkcolor}, % usual colors for online version of book is links are blue.  but for hard copy links are black

It’s a pity the ocgcolorlinks option is fragile – that would be my ideal rather than having 2 versions of the file.

That said the solution using \ifbool{hardcopybool} can be simplified down to:

\usepackage[\ifbool{hardcopybool}{hidelinks=true}{colorlinks=true}]{hyperref}

with a minimal version of the \usepackage line. If you want to add specific colours to links, you can add those back in to the “else” part of the \ifbool.

Why hidelinks=true rather than `colorlinks=false'? Because this way you avoid ugly boxes around hyperlinks.