Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Colored hyperref links

848 views
Skip to first unread message

Mariano Suárez-Alvarez

unread,
Mar 25, 2008, 6:20:31 PM3/25/08
to
Hi all,

is there a way to have hyperref produce links in the resulting
PDF file which are colored only when it is being viewed on screen,
but not when printed? In CSS-land, one would use

@media print { ... }
@media screen { ... }

to do such a thing; cf. <http://www.w3.org/TR/CSS21/media.html#media-
sheets>

Cheers.

-- m

vvvv

unread,
Mar 25, 2008, 9:39:36 PM3/25/08
to
On Mar 25, 6:20 pm, Mariano Suárez-Alvarez

<mariano.suarezalva...@gmail.com> wrote:
> Hi all,
>
> is there a way to have hyperref produce links in the resulting
> PDF file which are colored only when it is being viewed on screen,
> but not when printed?

I think the actual text of the hyperlink is written with LaTeX and
the clickable stuff is via PDF hacks. It might suffice to use a
custom color that doesn't look so bad, or use borders around the link
(the borders shouldn't print, or you should be able to alter the flags
so they don't print). The link feature uses the /Link annotation type
within the PDF. The flags that affect PDF annotations won't affect
the LaTeX text. See the PDF reference manual, section 8.4.2
"Annotation Flags"
http://www.adobe.com/devnet/acrobat/pdfs/pdf_reference.pdf

This shows a custom color for the link and an attempt to mannually
create a link:

\documentclass{memoir}
%
% also explore the pdfannotlink command
%
%
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{color}
\definecolor{mycolor}{rgb}{0.4,0.7,0.7}
% note that the colorlinks option of true removes
% the link border, but borders might not work in all browser
\hypersetup{bookmarks=true,colorlinks=true,urlcolor=mycolor,
urlbordercolor=0.3 0.9 0.3,citecolor=red,pdfmenubar=true,
pdfauthor={Your Name},pdfpagemode=None,
pdfpagelayout=TwoColumnRight,hyperfootnotes=true,
hyperfigures=true,hyperindex=true,pdfstartview=FitH}
%
%

\begin{document}
\setbox0=\hbox{test link}%
\edef\mywd{\wd0}%
\edef\myht{\ht0}%
\expandafter\pdfannot width \mywd height 14pt{
/Subtype /Link
/Contents (this is the main contents.)
/A << /Type/Action
/S/URI/URI(http://groups.google.com/group/comp.text.tex)
>>
}\box0

Regular hyperref test using custom color:
\rlap{hello}\href{http://reddit.com}{hello}
\end{document}

Will Robertson

unread,
Mar 25, 2008, 11:49:34 PM3/25/08
to
On Mar 26, 11:39 am, vvvv <vnes...@gmail.com> wrote:
> On Mar 25, 6:20 pm, Mariano Suárez-Alvarez
>
> <mariano.suarezalva...@gmail.com> wrote:
>
> > is there a way to have hyperref produce links in the resulting
> > PDF file which are colored only when it is being viewed on screen,
> > but not when printed?
>
>  I think the actual text of the hyperlink is written with LaTeX and
> the clickable stuff is via PDF hacks.

There is support in PDF for "optional content" (I've just been looking
in the v1.7 reference section 4.10) but I don't know how well
supported that kind of thing is outside of Acrobat Reader itself.

I haven't looked into it enough to know what to do next, but I really
like the idea of it. A PDF that could have colours when viewed on
screen and distinguishable black and white patterns when printed
greyscale would be pretty nice.

Will


Bil Kleb

unread,
Mar 26, 2008, 5:40:25 AM3/26/08
to
vvvv wrote:

> Mariano Suárez-Alvarez wrote:
>>
>> is there a way to have hyperref produce links in the resulting
>> PDF file which are colored only when it is being viewed on screen,
>> but not when printed?
>
> I think the actual text of the hyperlink is written with LaTeX and
> the clickable stuff is via PDF hacks. It might suffice to use a
> custom color that doesn't look so bad, [..]

This is route I've used in the past: make links dark blue:

\usepackage{color}\definecolor{darkblue}{rgb}{0,0,0.5}
\usepackage[hyperfootnotes=false,
colorlinks,urlcolor=darkblue,linkcolor=black]%
{hyperref}

And when I'm in control of printing, I just switch to
\usepackage{nohyperref].

I have no ideas for automating the switch, but it sure would
be nice. Although, I would also want a footnote to appear for
the printed version that informed them they are missing
something (links).

Regards,
--
Bil Kleb
http://twitter.com/bil_kleb

Mariano Suárez-Alvarez

unread,
Mar 26, 2008, 11:26:32 AM3/26/08
to

That's doable. But I after the possibility of having
both the links in color for on-screen viewing, and
everyhing in black for printing from te *same*
pdf file.

-- m

G. A. Edgar

unread,
Mar 26, 2008, 11:31:02 AM3/26/08
to
In article
<14803cce-6be5-4ec9...@a70g2000hsh.googlegroups.com>,
Mariano Suárez-Alvarez <mariano.su...@gmail.com> wrote:

> > >> is there a way to have hyperref produce links in the resulting
> > >> PDF file which are colored only when it is being viewed on screen,
> > >> but not when printed?


You have other color things in the document, so you cannot just print
in black&white ?

--
G. A. Edgar http://www.math.ohio-state.edu/~edgar/

Mariano Suárez-Alvarez

unread,
Mar 26, 2008, 12:01:07 PM3/26/08
to
On Mar 26, 12:31 pm, "G. A. Edgar" <ed...@math.ohio-state.edu.invalid>
wrote:
> In article
> <14803cce-6be5-4ec9-a22c-e28e2e9f0...@a70g2000hsh.googlegroups.com>,

>
> Mariano Suárez-Alvarez <mariano.suarezalva...@gmail.com> wrote:
> > > >> is there a way to have hyperref produce links in the resulting
> > > >> PDF file which are colored only when it is being viewed on screen,
> > > >> but not when printed?
>
> You have other color things in the document, so you cannot just print
> in black&white ?

Coloring the links is useful when viewing on screen because
it provides visual clue that there is a link. When the
document is printed, there is no point in having that clue,
because the link is not there anymore. Whether there be other
color things in the document does not change that ;-)

-- m

G. A. Edgar

unread,
Mar 26, 2008, 1:21:47 PM3/26/08
to
In article
<b248f69c-b8e7-4721...@13g2000hsb.googlegroups.com>,
Mariano Suárez-Alvarez <mariano.su...@gmail.com> wrote:

But having NO color things in the document makes it easy to print,
just choose black&white print. Isn't that what was desired in
the first place? Don't change the PDF file, instead change the
choices you make when you print.

Mariano Suárez-Alvarez

unread,
Mar 26, 2008, 3:03:36 PM3/26/08
to
On Mar 26, 2:21 pm, "G. A. Edgar" <ed...@math.ohio-state.edu.invalid>
wrote:
> In article
> <b248f69c-b8e7-4721-bdee-5c7463141...@13g2000hsb.googlegroups.com>,

>
>
>
> Mariano Suárez-Alvarez <mariano.suarezalva...@gmail.com> wrote:
> > On Mar 26, 12:31 pm, "G. A. Edgar" <ed...@math.ohio-state.edu.invalid>
> > wrote:
> > > In article
> > > <14803cce-6be5-4ec9-a22c-e28e2e9f0...@a70g2000hsh.googlegroups.com>,
>
> > > Mariano Suárez-Alvarez <mariano.suarezalva...@gmail.com> wrote:
> > > > > >> is there a way to have hyperref produce links in the resulting
> > > > > >> PDF file which are colored only when it is being viewed on screen,
> > > > > >> but not when printed?
>
> > > You have other color things in the document, so you cannot just print
> > > in black&white ?
>
> > Coloring the links is useful when viewing on screen because
> > it provides visual clue that there is a link. When the
> > document is printed, there is no point in having that clue,
> > because the link is not there anymore. Whether there be other
> > color things in the document does not change that ;-)
>
> > -- m
>
> But having NO color things in the document makes it easy to print,
> just choose black&white print. Isn't that what was desired in
> the first place? Don't change the PDF file, instead change the
> choices you make when you print.

At the risk of being repetitive, what was desired
in the first place was a way to have the PDF be
rendered differently accoding to the media it is
rendered to, in the specific aspect of the coloring
of the links it contains.

-- m

Mariano Suárez-Alvarez

unread,
Mar 26, 2008, 9:30:51 PM3/26/08
to

Indeed, section 4.10.3 looks like this should be possible...

-- m

vvvv

unread,
Mar 27, 2008, 1:12:45 PM3/27/08
to

> But having NO color things in the document makes it easy to print,
> just choose black&white print.  

sometimes the color links are printed in a lighter shade than ordinary
text, and sometimes that is distracting.

Jellby

unread,
Mar 28, 2008, 10:22:29 AM3/28/08
to
Among other things, Mariano Suárez-Alvarez saw fit to write:

> That's doable. But I after the possibility of having
> both the links in color for on-screen viewing, and
> everyhing in black for printing from te *same*
> pdf file.

I guess it could be possible, but I don't know how. If you have your links
"framed" (the default with hyperref, I think), the frame is not printed.
And I remember having some pdf file that printed big black circles over the
text, which were not present in the screen (but it could have been a bug in
the reader or in the printer driver...). There is the possibility of having
text in the screen which is not selected with the text-select tool (in
acroread)... So I would guess what you want is possible.

--
Ignacio __ Fernández Galván
/ /\
Linux user / / \ PGP Pub Key
#289967 / / /\ \ 0x01A95F99
/ / /\ \ \
http://djelibeibi.unex.es
/________\ \ \
jellby \___________\/ yahoo.com

Heiko Oberdiek

unread,
Apr 19, 2008, 1:14:49 PM4/19/08
to
Mariano Suárez-Alvarez <mariano.su...@gmail.com> wrote:

However 4.10.2 states that color settings are still applied.
Thus the link text must be put in a box and set twice, with
and without color.
Now hyperref v6.77r comes with an experimental option
`ocgcolorlinks' for pdftex and dvipdfm that uses Optional
Content Groups for colored links.

Yours sincerely
Heiko <ober...@uni-freiburg.de>

Mariano Suárez-Alvarez

unread,
Apr 19, 2008, 3:48:03 PM4/19/08
to
On Apr 19, 2:14 pm, Heiko Oberdiek <oberd...@uni-freiburg.de> wrote:

Great! :)

Thanks a real lot.

-- m

0 new messages