wkhtmltopdf:具有--TOC标题文本属性的自定义TOC样式

wkhtmltopdf:具有--TOC标题文本属性的自定义TOC样式,pdf,xslt,pdf-generation,wkhtmltopdf,tableofcontents,Pdf,Xslt,Pdf Generation,Wkhtmltopdf,Tableofcontents,我正在使用库生成带有选项的PDF文件 --toc-header-text TEXT --xsl-style-sheet config/wkhtmltopdf_toc.xsl 但是,--toc header text值不会插入到生成的目录中 有没有办法将--toc header text变量的值插入到自定义toc样式表中?好的,这不是答案,但可以解决问题 我为每个生成的pdf创建一个带有toc样式表的临时文件,用我的动态内容替换标题文本,并将该文件传递给wkhtmltopdf 在Ruby中,它可

我正在使用库生成带有选项的PDF文件

--toc-header-text TEXT --xsl-style-sheet config/wkhtmltopdf_toc.xsl
但是,
--toc header text
值不会插入到生成的目录中


有没有办法将
--toc header text
变量的值插入到自定义toc样式表中?

好的,这不是答案,但可以解决问题

我为每个生成的pdf创建一个带有toc样式表的临时文件,用我的动态内容替换标题文本,并将该文件传递给wkhtmltopdf

在Ruby中,它可以是:

toc_file = Tempfile.new
toc_content = File.
  read('config/wkhtmltopdf_toc.xsl').
  gsub(':index_title', title)
toc_file.write(toc_content)
toc_file.rewind
将文件路径传递给wkhtmltopdf--
toc_file.path

生成pdf后销毁文件:

toc_file.close
toc_file.unlink

好吧,这不是一个答案,但它是一个解决办法

我为每个生成的pdf创建一个带有toc样式表的临时文件,用我的动态内容替换标题文本,并将该文件传递给wkhtmltopdf

在Ruby中,它可以是:

toc_file = Tempfile.new
toc_content = File.
  read('config/wkhtmltopdf_toc.xsl').
  gsub(':index_title', title)
toc_file.write(toc_content)
toc_file.rewind
将文件路径传递给wkhtmltopdf--
toc_file.path

生成pdf后销毁文件:

toc_file.close
toc_file.unlink

使用XSLT magic根据第一个大纲项(即TOC本身)的名称定义变量

我这样做:

<xsl:variable name="tocTitle" select="//outline:outline/outline:item[1]/@title" />
<xsl:template match="outline:outline">
    <html>
    <head>
        <title><xsl:value-of select="$tocTitle" /></title>
    ...
    </head>
    <body>
        <h1><xsl:value-of select="$tocTitle" /></h1>
        <ul><xsl:apply-templates select="outline:item/outline:item"/></ul>
    </body>
    </html>
...

...
    ...

    这是痛苦的尝试和错误(我不是这方面的专家,如果我做错了,很高兴有人纠正我)。我一直在胡思乱想,直到它成功。

    使用XSLT magic根据第一个大纲项(即TOC本身)的名称定义一个变量

    我这样做:

    <xsl:variable name="tocTitle" select="//outline:outline/outline:item[1]/@title" />
    <xsl:template match="outline:outline">
        <html>
        <head>
            <title><xsl:value-of select="$tocTitle" /></title>
        ...
        </head>
        <body>
            <h1><xsl:value-of select="$tocTitle" /></h1>
            <ul><xsl:apply-templates select="outline:item/outline:item"/></ul>
        </body>
        </html>
    ...
    
    
    ...
    
      ...
      这是痛苦的尝试和错误(我不是这方面的专家,如果我做错了,很高兴有人纠正我)。我一直胡闹直到成功