FOP XSL-FO Anchor in an external destination

杀马特。学长 韩版系。学妹 提交于 2019-12-05 18:02:18

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/14703548/fop-xsl-fo-anchor-in-an-external-destination

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!