19

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?

2
  • 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
19

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

1
3

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.

3

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
1
  • 1
    Your \usepackage[...., ends basically in the middle of nowhere
    – user31729
    Mar 1 '15 at 11:30
1

use colorlinks=false this =nocolor. colorlinks=true this=linkcolor here blue. for example

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

nocolor and

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

bleu

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.