【问题】
已经实现了去掉带链接的文字后面的url链接,但是想要pdf中的带链接的文字,都像html中的一样,颜色为蓝色,且带下划线。
即,pdf中是这样的:
想要实现html中的这样的效果:
【解决过程】
1.折腾这个:
【已解决】去掉docbook中输出的pdf中,除了带链接的文字之外的那个链接地址
的过程中,知道了,原来可以通过参数控制很多东西,然后就去找了和ulink相关的参数:
Part 2. FO Parameter Reference – Miscellaneous
中的
ulink.show — Display URLs after ulink
s?ulink.footnotes — Generate footnotes for ulink
s?ulink.hyphenate — Allow URLs to be automatically hyphenated ulink.hyphenate.chars — List of characters to allow ulink URLs to be automatically hyphenated on
但是其中没有找到,可以给ulink添加下划线这方面的参数。
所以,只能继续找其他办法。
2.参考:
Underline and color internal links (<link/>) in docbook PDF output
找到patch:
https://jira.springsource.org/secure/attachment/13244/underline-internal-links.patch
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | --- spring/docs/reference/styles/fopdf.xsl 2007-07-10 09:33:23.000000000 -0700 +++ ../../springsource/spring-javaconfig/trunk/src/docbkx/resources/xsl/fopdf.xsl 2008-01-03 11:06:06.000000000 -0800 @@ -475,4 +477,21 @@ </fo:basic-link> </xsl:template> + + <xsl:template match="link"> + <fo:basic-link internal-destination="{@linkend}" + xsl:use-attribute-sets="xref.properties" + text-decoration="underline" + color="blue"> + <xsl:choose> + <xsl:when test="count(child::node())=0"> + <xsl:value-of select="@linkend"/> + </xsl:when> + <xsl:otherwise> + <xsl:apply-templates/> + </xsl:otherwise> + </xsl:choose> + </fo:basic-link> + </xsl:template> + </xsl:stylesheet> |
接下来,就要搞清楚,这些配置,应该是加到哪个文件的哪个位置中去。
找了下,这个文件:
E:\dev_install_root\cygwin\usr\share\sgml\docbook\xsl-ns-stylesheets\fo\xref.xsl
中有fo:basic-link方面的配置,应该就是这个文件了。
但是具体放到哪个位置,目前还是不清楚。
3.折腾了一下,本来是打算把这部分配置,放到我自己的xls配置文件docbook_fo_crl_yahei.xsl的,结果没有生效,所以,试了试,结果证实:
(1)方法1:手动把:
1 2 | text-decoration="underline" color="blue" |
添加到xref.xsl中的对应的位置,变成:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | < xsl:template match = "d:ulink" name = "ulink" > < xsl:param name = "url" select = "@url" /> < xsl:variable name = "ulink.url" > < xsl:call-template name = "fo-external-image" > < xsl:with-param name = "filename" select = "$url" /> </ xsl:call-template > </ xsl:variable > < fo:basic-link xsl:use-attribute-sets = "xref.properties" external-destination = "{$ulink.url}" text-decoration = "underline" color = "blue" > < xsl:choose > < xsl:when test = "count(child::node())=0 or (string(.) = $url)" > < xsl:call-template name = "hyphenate-url" > < xsl:with-param name = "url" select = "$url" /> </ xsl:call-template > </ xsl:when > < xsl:otherwise > < xsl:apply-templates /> </ xsl:otherwise > </ xsl:choose > </ fo:basic-link > <!-- * Call the template for determining whether the URL for this --> <!-- * hyperlink is displayed, and how to display it (either inline or --> <!-- * as a numbered footnote). --> < xsl:call-template name = "hyperlink.url.display" > < xsl:with-param name = "url" select = "$url" /> < xsl:with-param name = "ulink.url" select = "$ulink.url" /> </ xsl:call-template > </ xsl:template > |
(2)方法2:复制原先的xref.xsl,另存为一个新的xref_crl.xsl,然后改动为上面的内容后,在原先的docbook_fo_crl_yahei.xsl中导入该文件:
1 | < xsl:import href = "xref_crl.xsl" /> |
两种方法都可以,最后的生成的pdf效果如下:
【总结】
想要实现pdf中的链接,颜色为蓝色,且带下划线的话,就是把:
text-decoration="underline"和 color="blue"
添加到对应的xref中的ulink中的fo:basic-link部分,即可。
即,由:
1 2 | < fo:basic-link xsl:use-attribute-sets = "xref.properties" external-destination = "{$ulink.url}" > |
变成:
1 2 3 4 | < fo:basic-link xsl:use-attribute-sets = "xref.properties" external-destination = "{$ulink.url}" text-decoration = "underline" color = "blue" > |
【后记 2012-06-05】
后来发现,有更加好的方法,那就是不去改原先的xsl文件,而添加如下配置即可:
1 2 3 4 5 6 7 8 | <!--============================================================================ xref underline setting =============================================================================--> < xsl:attribute-set name = "xref.properties" > < xsl:attribute name = "color" >blue</ xsl:attribute > <!-- http://www.w3schools.com/cssref/pr_text_text-decoration.asp: overline/line-through/underline --> < xsl:attribute name = "text-decoration" >underline</ xsl:attribute > </ xsl:attribute-set > |
这样,凡是xref类型的,包括link,都可以应用此配置了,即蓝色,带下划线。