title: openhtmltopdf / flying saucer: many links in huge PDF are not clickable (PDF annotations not set)
body: <p>I generate huge catalogs (~ 1500 pages) as HTML and convert is via Jsoup to and <a href="https://github.com/danfickle/openhtmltopdf" rel="nofollow noreferrer">openhtmltopdf</a> (which uses flying saucer) to PDF. In the resulting PDF many links are not clickable, and I can't find out why. </p>
  
  <p>Consider the following program:</p>
  
  <pre><code>import org.jsoup.helper.W3CDom;
  import org.w3c.dom.Document;
  import org.jsoup.Jsoup;
  import com.openhtmltopdf.pdfboxout.PdfRendererBuilder;
  import java.io.File;
  import java.io.FileOutputStream;
  import java.io.IOException;
  
  public class Main {
  
      public static void main(String[] args) throws Exception {
  
          PdfRendererBuilder pdfBuilder = new PdfRendererBuilder();
  
          String html = "&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;";
          for (Integer i = 0; i &lt; 10000; i++) {
              html += "&lt;a href='http://www.google.de?q=" + i + "'&gt;blabla&lt;/a&gt;    &lt;br&gt;";
          }
          html += "&lt;/body&gt;&lt;/html&gt;";
  
          File file = new File("/tmp/tmp.pdf");
          FileOutputStream fop = new FileOutputStream(file);
  
          W3CDom w3cDom = new W3CDom();
          Document w3cDoc = w3cDom.fromJsoup(Jsoup.parse(html));
  
          pdfBuilder.withW3cDocument(w3cDoc, "/");
          pdfBuilder.toStream(fop);
          try {
              pdfBuilder.run();
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>
  
  <p>It creates a PDF with 176 pages and 10.000 links. On page 1 to 3 they are clickable, afterwards they are not, although identical. The last clickable link is the number 112 and in the source code I find:</p>
  
  <pre><code>870 0 obj
  &lt;&lt;
  /W 0.0
  /S /S
  &gt;&gt;
  endobj
  871 0 obj
  &lt;&lt;
  /S /URI
  /URI (http://www.google.de?q=111)
  &gt;&gt;
  endobj
  872 0 obj
  &lt;&lt;
  /W 0.0
  /S /S
  &gt;&gt;
  endobj
  873 0 obj
  &lt;&lt;
  /S /URI
  /URI (http://www.google.de?q=112)
  &gt;&gt;
  endobj
  874 0 obj
  &lt;&lt;
  /W 0.0
  /S /S
  &gt;&gt;
  endobj
  875 0 obj
  &lt;&lt;
  /F1 1049 0 R
  &gt;&gt;
  endobj
  </code></pre>
  
  <p>Apparently after number 112 there are no URLs stored anymore in the annotation objects.</p>
  
  <p>My Program is much more complicated naturally. On the first five or six pages of it's result all the links are clickable, after that some are and most are not. Which ones are still clickable seems to be completely random though.</p>
  
  <p>Can anyone help here? Any Idea what may cause this issue or how to fix it? A bug in openhtmltopdf?</p>
  
  <p>-- </p>
  
  <p>edit 1:
  Using withHtmlContent instead of withW3cDocument has the same problem.</p>