在html中预览xslt到pdf的转换



我已经创建了使用Apache FOP从XML转换为pdf的代码和xslt。现在我需要预览关于更改xslt的pdf。它应该被视为Html页面。我做不到。有人能帮我吗?谢谢。

下面的代码是用于试验的其他数据我已经添加了A p J Abdul Kalam

xslt

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">

<xsl:template match="/">
<fo:root>
<fo:layout-master-set>
<fo:simple-page-master master-name="simpleA4" page-height="29.7cm" page-width="21.0cm" margin="1cm">
<fo:region-body region-name="xsl-region-body" margin-top="1cm" margin-bottom="1cm"/>
<fo:region-before region-name="xsl-region-before" extent="1cm"/>
<fo:region-after region-name="xsl-region-after" extent="1cm"/>
</fo:simple-page-master>
</fo:layout-master-set>

<fo:page-sequence master-reference="simpleA4">
<fo:static-content flow-name="xsl-region-before">
<fo:block text-align="left" font-family="Helvetica" color="green" font-size="16pt" font-weight="bold"><xsl:value-of select="data/title"/></fo:block>
</fo:static-content>

<fo:static-content flow-name="xsl-region-after">
<fo:block text-align="right" font-size="11pt">Page <fo:page-number/> of <fo:page-number-citation ref-id="last-page"/></fo:block>
<fo:block text-align="center" font-size="8pt">Copyright&#169; 2022 Creation, All rights Reserved</fo:block>
</fo:static-content>

<fo:flow flow-name="xsl-region-body">
<fo:block text-align="justify" font-family="Helvetica" color="black" font-size="13pt" space-after="3mm">
<xsl:value-of select="data/Para"/>
</fo:block>

<fo:block text-align="justify" font-family="Helvetica" color="black" font-size="13pt" space-after="3mm">
<xsl:value-of select="data/Para[2]"/>
</fo:block>

<fo:block text-align="justify" font-family="Helvetica" color="black" font-size="13pt" space-after="3mm">
<xsl:value-of select="data/Para[3]"/>
</fo:block>

<fo:block text-align="justify" font-family="Helvetica" color="black" font-size="13pt" space-after="3mm">The details have been fetched from 
<fo:basic-link font-family="Helvetica" color="red" font-size="11pt" font-weight="bold" external-destination="url(https://en.wikipedia.org/wiki/A._P._J._Abdul_Kalam)"> https://en.wikipedia.org/wiki/A._P._J._Abdul_Kalam</fo:basic-link></fo:block>

<fo:block id="last-page"/>
</fo:flow>         
</fo:page-sequence>
</fo:root>
</xsl:template>
</xsl:stylesheet>

数据xml

<?xml version="1.0" encoding="UTF-8"?>
<data>
<title>A P J Abdul Kalam</title>
<url>https://en.wikipedia.org/wiki/A._P._J._Abdul_Kalam</url>
<Para>
Avul Pakir Jainulabdeen Abdul Kalam;was born on 15 October 1931 – 27 July 2015) was an Indian aerospace scientist 
who served as the 11th president of India from 2002 to 2007. He was born and raised in Rameswaram, Tamil Nadu and studied physics and aerospace engineering. 
He spent the next four decades as a scientist and science administrator, mainly at the Defence Research and Development Organisation (DRDO) and 
Indian Space Research Organisation (ISRO) and was intimately involved in India's civilian space programme and military missile development efforts. 
He thus came to be known as the Missile Man of India for his work on the development of ballistic missile and launch vehicle technology. He also played a 
pivotal organisational, technical, and political role in India's Pokhran-II nuclear tests in 1998, the first since the original nuclear test by India in 1974.
</Para> 
<Para>
Kalam was elected as the 11th president of India in 2002 with the support of both the ruling Bharatiya Janata Party and the then-opposition Indian 
National Congress. Widely referred to as the "People's President",[6] he returned to his civilian life of education, writing and public service after a single 
term. He was a recipient of several prestigious awards, including the Bharat Ratna, India's highest civilian honour.
</Para>   
<Para>
While delivering a lecture at the Indian Institute of Management Shillong, Kalam collapsed and died from an apparent cardiac arrest on 27 July 2015, 
aged 83. Thousands, including national-level dignitaries, attended the funeral ceremony held in his hometown of Rameswaram, where he was buried with full state 
honours.
</Para>
</data>

浏览器呈现HTML。XSL FO不是HTML,也不会在浏览器中呈现。对于您的请求,唯一真正的解决方案是将其呈现到PDF服务器端并向他们显示PDF。这应该很容易,这是你的问题吗?如果是,则显示用于生成PDF的服务器端代码,并将其发送回浏览器。

如果您认为可以通过XSL FO到HTML的转换来模拟PDF。算了吧,这不是真的。没有真正的紧排,字体必须相同,还有许多其他限制(保留、页面等(

您可以编写甚至在Safari、Firefox、Edge和Chrome中都不呈现相同内容的HTML。认为您可以将XSL FO转换为HTML进行预览是一个梦想。

一些引擎支持SVG分页输出或XHTML输出,这些输出试图模拟转换,但它只有在浏览器呈现内容时才是最好的。

最新更新