Forum Samples, Tips and Tricks

Outline PDF links

Prince currently has fairly little support for PDF annotations, which you need to use to make the screen and print version of the PDF different. I underline my hyperlinks on my site, but there is no point using different styles for internal page links in ToC, Indices, and so on. So, the print version of the PDF has plain (unstyled) links, but I wanted to distinguish them visually when looking at the PDF on screen, because you can of course still click on them. I did this by adding borders to the Link annotations, post-processing the Prince PDF using PDFedit. This was new to me, but it was all surprisingly easy. PDF is a rather neat and tidy format, very easy to learn.

This is my solution:
// Console: dropAnnotation
// Description: Remove the first annotation from the first page of a file
// Parameters: [input file]

function onConsoleStart() {

if (name = takeParameter()) {
  var document = loadPdf(name, false);
  for (var i = 1; i <= document.getPageCount(); ++i) {
    var page = document.getPage(i).getDictionary();
    if (!page.exist("Annots")) continue;
    var annots = page.child("Annots");
    for (var j = 0; j < annots.count(); ++j) {
      var annot =;
      if (annot.exist("Subtype") &&"Subtype").value() == "Link") {"Border").delProperty(2);"Border").add(createInt(1));
        annot.add("C", createArray());
        var C ="C").ref();
} else {
  print('Error: specify a file');

I run it from my automation framework using
pdfedit -s <path>/script.qs <doc>.pdf
and get beautiful results! Example:

I would be glad to hear if there is an easier way to do this. If anyone else wants to give it a go, Adobe very kindly provide an extremely readable spec:
I've got a neat CSS trick to deal with links:

/* External links should show their URL */
	a[href]			{color: #0159A0};
	a[href]:after	{content: " (" attr(href) ")";}
	/* Internal links don't need it */
		a[href^="#"]		{color: #A00601;}
		a[href^="#"]:after	{content: "";}

Which does this:

  • Internal links like <a href="#heading">... are red
  • External links like <a href="everythingelse">... are blue AND have the URL appended to them to be referenced during print :-)

PS - am new to printing nomenclature so I may have misinterpreted the post