我想使用PDFReactor从xslt生成pdf,但我有一个问题:PDFReactor没有将base64图像附加到pdf
(...)
<img>
<xsl:attribute name="src">
data:image/png;base64,<xsl:value-of select="ksx:image"/>
</xsl:attribute>
</img>
(...)
PDFReactor支持在xslt文件中附加图像吗?
答案 0 :(得分:0)
这应该在PDFreactor中有效。这是一个简单的测试用例:
<强> XML:强>
<?xml-stylesheet type="text/xsl" href="test.xsl" ?>
<ksx:root xmlns:ksx="http://www.ksx.com/ns">
<ksx:image>R0lGODlhKgAqAPYAAAAAAAAAFAAAMQQUAAgAFAwEIRAEABAAEBQMABgAABgUABghACEEACEQACEhADEAEHt7a4iEd4wxGIyEjIyEpZCMb5aSeZaYlpyQpZyYqZyYuZychJylkJylpaWcnKWcxqWpqaursampvamxxrGxsbWlzrW1lLW5ube3yrW9hL250r293r3Grb3KvcYYCMa158a9rca91srKucbGysbG78bOrcjQys7K0s7S0tLWudTU2tbWytba69ra+9bextre1t4IAN7W697eEN7eKd7e3t7e597nCN7nxt7n1t7n797vQufe7+fnEOfnIerq2uzq6+vr++vvAOzsMefvRuv7FO39Au8AAO8AOe/z6/Pv/+/7Je/3QvP73u/77/sADPfrAPfvDPvrIffz5/f3BPf3FPf38/////f/BPf/FP39Jfz/Nv8AGP8IAP8QGP/zAP/zFP/8Bf/7FP//Qv//Wv//7wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAUAAAsALAAAAAAqACoAAAf/gAuCg4JmhXRmhoOKiogLioSRkoSJkAtZZmWPZWVimJWJWZOjkomCUI8/T2I/Tk9PSWZJj4J0pLeJWGJiSD86OjYyMjPBOS1mPFhcmrejiWVcTjY6MygiGh4dFxkgIjYsOD1LT1zNk2VdTze/GR8UBQADAPPzExckKjyqnOaCnFyqYoSAoACAAyZqosCJcyaOlIIGKqRg0eNVvwWcjtxAgSGeEi1v4sCB42ZkySpppgAIcGEEEYulaGXicsTGCgsAEohMQ3JkwzELgcJJYwAAhhc7jnQxtchQoi6+S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LJkQwjwNCqHFay2hUURDIHtSAg0WZ9GNGND+4gQxC4A4b0WMeAYjABkKAgh34oAtlqETkSEEkIokMBycQgQpAAAIOXAAEF0ABCYiAgh5gYUGUOB8plOE7V+BAgPCygQ1yEAQicCELS3DERQhBh62ZYVqvcEsQnzCtx2HEFircoT84wUR+JFGJ/oPiIAIBADs=</ksx:image>
</ksx:root>
<强> XSL:强>
<xsl:stylesheet version="1.0" xmlns:ksx="http://www.ksx.com/ns" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="ksx:root">
<html>
<body>
<img>
<xsl:attribute name="src">
data:image/png;base64,<xsl:value-of select="ksx:image"/>
</xsl:attribute>
</img>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
如果您不使用XSL生成完整的HTML文档,则需要设置postTransformationDocumentType
以便PDFreactor知道您正在生成HTML。您可以这样设置:
pdfReactor.setPostTransformationDocumentType(PDFreactor.DOCTYPE_HTML5);
还要记得像这样启用XSLT处理:
pdfReactor.setXSLTMode(true);