[pdftex] Is hyperref link color stored in PDF file annotation data?

Ross Moore ross.moore at mq.edu.au
Sun Jan 3 21:18:01 CET 2021


Hi Doug,

On 3 Jan 2021, at 1:58 pm, Doug McKenna <doug at mathemaesthetics.com<mailto:doug at mathemaesthetics.com>> wrote:

When I create a PDF using XeTeX (via TeXShop on MacOS), I use the hyperref package to create intra-document links.

I use the following to set the link color for them:

\hypersetup{
  linkcolor =[rgb]{0.4,0.1,0.4},    % Darkish purple
  colorlinks=true
  }

It all works as advertised.

Yes. it sets the colour of the anchor text in the body of your PDF document.


I then open the built PDF file using a MacOS-based PDF viewer that I've built using Apple's PDFKit stuff (which allows me to query the PDF for various properties, among other things).  After much learning and hacking away (in Swift), all that seems to work.

I can get information about a link area on a PDF page (such as the rectangle containing the link-colored text), all of which is contained in what is called an annotation.  One of an annotation's properties is ... |color|.


This is not the same colour at all.
It could be referring to one of several possible uses for a colour,
as in the image:

[cid:7f3bd736-2581-4861-8693-6029840e3240 at ausprd01.prod.outlook.com]

Other possible colour specifications are:

  • /BC  border colour – used to draw the border of a popup window,
 •  /IC   interior colour – for graphical objects that the annotation may draw;
 e.g., circle, rectangle, polygon, etc.

… but these are entries in associated dictionaries, not the main annotation dictionary itself.
Generally, for links which have just an invisible rectangle, these are not applicable.
 … and then there are also “appearance streams” which allow for an awful lot more.


With hyperref, you need to be pretty much clued-in to PDF syntax to specify these.
They are done using the optional argument to hyperref-provided macros.
You really have to know exactly what you are doing, to be able to use them.



But when I access this |color| property, it is always red, regardless of how linkcolor in the TeX file was originally set.  So the link color installed into the PDF (using pdfTeX primitives or \specials or whatever) would appear to be part of some other part of the annotation.

Questions:

How is hyperref's linkcolor stored in a PDF file?

It occurs within the page content stream, just giving coloured text on the page.
It actually has *no connection at all* with the annotation.

Here’s an example, of the internal PDF coding produced, in the attached PDF:

/F15 10.9091 Tf 0 -24.352 Td [(Link)-333(to)]TJ
0.4 0.1 0.4 rg 0.4 0.1 0.4 RG  %%% <<—   colour changes here!
 [-334(1)]TJ
0 g 0 G
 [(.)]TJ
0 g 0 G
 211.472 -404.141 Td [(1)]TJ
0 g 0 G
ET


Here’s what the annotation looks like, internally:

% 8 0 obj
<<
/Type /Annot
/Subtype /Link
/Border[0 0 0]/H/I/C[1 0 0]
/Rect [129.441 515.819 136.888 525.387]
/A << /S /GoTo /D (section.1) >>
>>

The bit   /C[1 0 0]  is the red that you described.
It is altered in hyperref using:

\hypersetup{
  linkcolor =[rgb]{0.4,0.1,0.4},    % Darkish purple
  linkbordercolor=[rgb]{0.4,0.1,0.4},
  colorlinks=true
  }

% 8 0 obj
<<
/Type /Annot
/Subtype /Link
/Border[0 0 0]/H/I/C[.4 .1 .4]
/Rect [129.441 515.819 136.888 525.387]
/A << /S /GoTo /D (section.1) >>
>>



External hyperlinks use  urlbordercolor=…
and there are others. See e.g., p.64 of The LaTeX Web Companion.


Is it possible to determine from the PDF file itself what that color is in a structured, official way?

No.

Is there some special key value being used?

No.


Or is it a brute force thing where the PDF data can't distinguish from generalized colored text?

Yes.



Doug McKenna
Mathemaesthetics, Inc.


Hope this helps.

Ross




Dr Ross Moore
Department of Mathematics and Statistics
12 Wally’s Walk, Level 7, Room 734
Macquarie University, NSW 2109, Australia
T: +61 2 9850 8955  |  F: +61 2 9850 8114
M:+61 407 288 255  |  E: ross.moore at mq.edu.au<mailto:ross.moore at mq.edu.au>
http://www.maths.mq.edu.au
<http://mq.edu.au/>
[cid:595813d7-2da1-4abe-91e3-4475e3e58158 at ausprd01.prod.outlook.com]

CRICOS Provider Number 00002J. Think before you print.
Please consider the environment before printing this email.

This message is intended for the addressee named and may
contain confidential information. If you are not the intended
recipient, please delete it and notify the sender. Views expressed
in this message are those of the individual sender, and are not
necessarily the views of Macquarie University. <http://mq.edu.au/>
<http://mq.edu.au/>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://tug.org/pipermail/pdftex/attachments/20210103/2f0ca6d3/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screen Shot 2021-01-04 at 6.36.08 am.png
Type: image/png
Size: 58815 bytes
Desc: Screen Shot 2021-01-04 at 6.36.08 am.png
URL: <https://tug.org/pipermail/pdftex/attachments/20210103/2f0ca6d3/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.png
Type: image/png
Size: 4605 bytes
Desc: image001.png
URL: <https://tug.org/pipermail/pdftex/attachments/20210103/2f0ca6d3/attachment-0003.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: texshop_image.pdf
Type: application/pdf
Size: 48813 bytes
Desc: texshop_image.pdf
URL: <https://tug.org/pipermail/pdftex/attachments/20210103/2f0ca6d3/attachment-0001.pdf>


More information about the pdftex mailing list.