最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】给docbook生成的pdf中的带链接的文字,添加下划线和设置字体颜色为蓝色

Docbook crifan 3152浏览 0评论

【问题】

已经实现了去掉带链接的文字后面的url链接,但是想要pdf中的带链接的文字,都像html中的一样,颜色为蓝色,且带下划线。

即,pdf中是这样的:

去掉了url显示

想要实现html中的这样的效果:

html中的链接是蓝色且带下划线的

【解决过程】

1.折腾这个:

【已解决】去掉docbook中输出的pdf中,除了带链接的文字之外的那个链接地址

的过程中,知道了,原来可以通过参数控制很多东西,然后就去找了和ulink相关的参数:

Part 2. FO Parameter Reference – Miscellaneous

中的

ulink.show — Display URLs after ulinks?
ulink.footnotes — Generate footnotes for ulinks?
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

--- 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:手动把:

text-decoration="underline"
                color="blue"

添加到xref.xsl中的对应的位置,变成:

<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中导入该文件:

<xsl:import href="xref_crl.xsl"/>

两种方法都可以,最后的生成的pdf效果如下:

pdf中的链接也是蓝色且带下划线了

【总结】

想要实现pdf中的链接,颜色为蓝色,且带下划线的话,就是把:

text-decoration="underline"和 color="blue"

添加到对应的xref中的ulink中的fo:basic-link部分,即可。

即,由:

  <fo:basic-link xsl:use-attribute-sets="xref.properties"
                 external-destination="{$ulink.url}">

变成:

  <fo:basic-link xsl:use-attribute-sets="xref.properties"
                 external-destination="{$ulink.url}"
                 text-decoration="underline"
                color="blue">

【后记 2012-06-05】

后来发现,有更加好的方法,那就是不去改原先的xsl文件,而添加如下配置即可:

<!--============================================================================
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,都可以应用此配置了,即蓝色,带下划线。

转载请注明:在路上 » 【已解决】给docbook生成的pdf中的带链接的文字,添加下划线和设置字体颜色为蓝色

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
82 queries in 0.171 seconds, using 22.05MB memory