# Can I have hyperlinks a different color for printing?

Is it possible to print hyperlinks in the same colour as the surrounding text when printing a hard copy of a PDF?

When a PDF is printed on paper I would like the links to be the same colour as the surrounding text. Is this possible?

• You could specify to not print the markup, e.g. in Acrobat reader, i.e. the links should be printed in the standard textcolor then
– user31729
Mar 1 '15 at 11:16
• Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. Mar 1 '15 at 11:58

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

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.

  \usepackage[ocgcolorlinks]{hyperref}


....

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".

• This restriction has been lifted by the ocgx2 package, which allows for ocg colour links wrapping around line and page breaks. Apr 11 '17 at 10:33

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.

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[

• Your \usepackage[...., ends basically in the middle of nowhere
– user31729
Mar 1 '15 at 11:30

\usepackage[colorlinks=false,linkcolor=bleu]{hyperref}

\usepackage[colorlinks=true,linkcolor=bleu]{hyperref}
`