title: Define background color and transparency of link annotation in PDF
body: <p>The following code corresponds to a minimal PDF page with a link annotation defined by a rectangle and a text inside it:</p>
  
  <pre><code>%PDF-1.4
  1 0 obj
  &lt;&lt;/Type/Catalog /Pages 3 0 R&gt;&gt;
  endobj
  3 0 obj
  &lt;&lt;/Type/Pages/Kids[4 0 R]/Count 1&gt;&gt;
  endobj
  4 0 obj
  &lt;&lt;/Type/Page/Parent 3 0 R/MediaBox [ 0 0 612 792]/Resources&lt;&lt;/ProcSet[/PDF/Text]/Font&lt;&lt;/F1 &lt;&lt;/Type/Font/Subtype/Type1/Name/F1/BaseFont/Helvetica/Encoding/MacRomanEncoding&gt;&gt;&gt;&gt;&gt;&gt;/Contents 2 0 R/Annots [&lt;&lt;/Type/Annot/Subtype/Link/Rect[100 400 350 450]/Border[0 0 1]/C[0 1 1]/A&lt;&lt;/S/URI/URI(https://stackoverflow.com)&gt;&gt;&gt;&gt;]&gt;&gt;
  endobj
  2 0 obj
  &lt;&lt;/Length 59&gt;&gt;
  stream
  BT /F1 24 Tf 1 0 0 1 115 415 Tm (Go to StackOverflow)Tj
  ET
  endstream
  xref
  0 5
  0000000060 65535 f
  0000000009 00000 n
  0000000441 00000 n
  0000000055 00000 n
  0000000106 00000 n
  trailer
  &lt;&lt;/Size 5 /Root 1 0 R&gt;&gt;
  startxref
  540
  %%EOF
  </code></pre>
  
  <p><strong>How can I set the background color and transparency of the annotation</strong>? For example, I want to <em>make the background</em> (of the link box, not of the whole page) <em>cyan but still be able to read the text "Go to Stackoverflow"</em>. </p>
  
  <p>I've checked the ISO standard but it's a horrible text. It seems it could be through "Appearance Streams" (Annotation Properties a.k.a. /AP) but can't quite figure out how to do it. I was hoping though there is a more straightforward way (à la /C [ 0 1 1] ) that I might be missing. </p>
  
  <p>I´m trying to learn to write PDF files from scratch as a first step write my own code for manipulating PDFs. Also, learning some things I want may help in hacking some already available library w/o wasting time in deciphering code I don´t need.</p>
  
  <p>Thanks.</p>
  
  <p>Note: If you copy&amp;paste the code to test it, make sure the last character of each line is a newline, i.e., no space nor tabs after the last visible character. The byte counts seen depend on this. </p>
  
  <p>EDIT: The annotation appearance of mine which I have problems getting it to work with. 
  The annotation entry</p>
  
  <pre><code>&lt;&lt;/Type/Annot/Subtype/Link/Rect 7 0 R/Border[0 0 1]/C[0 1 1]/A 8 0 R/AP 10 0 R/AS/N&gt;&gt;
  </code></pre>
  
  <p>and the corresponding form XObject</p>
  
  <pre><code>10 0 obj
  &lt;&lt;/Type XObject/Subtype Form/BBox[100 400 350.0 450.0]/Resources 4 0 R/Length 74&gt;&gt;
  stream
  4 w q /GS0 gs 105.0 405.0 240.0 040.0 re 1.0 0.0 0.0 rg 0.0 0.0 1.0 RG B Q
  endstream
  endobj
  </code></pre>
  
  <p>I get no link highlighting nor border on screen as per this form.</p>