我正在使用wkhtmltopdf库生成带选项的PDF文件
--toc-header-text TEXT --xsl-style-sheet config/wkhtmltopdf_toc.xsl但是--toc-header-text值不会插入到生成的目录中。
有没有办法将--toc-header-text变量的值插入到自定义目录样式表中?
发布于 2017-02-07 07:35:22
好吧,这不是一个答案,但它是解决办法
我使用toc样式表为每个生成的pdf创建了一个temp文件,用我的动态内容替换了标题文本,并将该文件传递给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发布于 2019-02-24 06:06:53
使用XSLT魔术根据第一个大纲项(即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>
...这是一个痛苦的尝试和错误(我不是这方面的专家,如果我做错了,很高兴有人能纠正我)。我在https://www.freeformatter.com/xsl-transformer.html上胡闹,直到它起作用。
https://stackoverflow.com/questions/42073687
复制相似问题