Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FOP XSL-FO Anchor in an external destination

With XSL-FO (Fop), I succeeded in creating a link to an external PDF :

<fo:basic-link show-destination="new">
<xsl:attribute name="external-destination">foo.pdf</xsl:attribute>
</fo:basic-link>

But now, I would like to reach an anchor in this external PDF. So I tried to build something like that :

<fo:basic-link show-destination="new">
<xsl:attribute name="external-destination">foo.pdf#anchorId</xsl:attribute>
</fo:basic-link>

Unfortunately, when I click on the generated link, I get an error. It tries to open the document foo.pdf%23anchorId.

In my .fo file, the link is correct with a # but this # is misinterpreted during the transformation in PDF.

Do you have an idea to solve this issue ?

Thanks,

Johann

like image 531
Johann Avatar asked Feb 05 '13 08:02

Johann


1 Answers

For FOP we have two of link: Internal and External.

For External you may use:

   <fo:basic-link 
    external-destination="url('http://www.paulmccartney.com')" 
    color="blue" text-decoration="underline">
     Paul McCartney
   </fo:basic-link>

and Internal links are links from one location in a document to another location in the same document. There are two steps to creating internal links:

First, Give a unique ID to the location being linked to. IDs are specified with the id attribute. The value can be hard coded or generated. In the example below, we use the generate-id() XSLT function to generate IDs:

<fo:block font-weight="bold" font-size="larger" 
 id="{generate-id(.)}" break-before="page">
  <xsl:value-of select="."/>
 </fo:block>

Second, Create the link to that location. As with external links, internal links are created with the tag. The internal-destination attribute should be set to the value of an ID elsewhere in the document.

<fo:basic-link internal-destination="{generate-id(.)}">
 <xsl:value-of select="."/>
</fo:basic-link>

I think you missed to include 'url' keyword in 'external-destination' attribute

like image 67
Navin Rawat Avatar answered Oct 26 '22 23:10

Navin Rawat