适用于linux的软件-使用xsl将xml转换为pdf

Mil*_*sko 1 html xml pdf xslt

我有两个文件。

我想用这两个文件创建pdf。

  1. 有谁知道Linux上的程序可以做到这一点?
  2. 命令是什么?

第一个是xhtml / xml文件:

<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<table border="1">
    <tr>
        <td>Day/Time</td>
        <td>7.30</td>
        <td>8.15</td>
        <td>9.05</td>
        <td>9.50</td>
        <td>10.40</td>
        <td>11.25</td>
        <td>12.15</td>
        <td>13.00</td>
        <td>13.50</td>
        <td>14.35</td>
        <td>15.25</td>
        <td>16.10</td>
        <td>17.00</td>
        <td>17.45</td>
        <td>18.35</td>
    </tr>
    <tr>
        <td>Monday</td>
        <td colspan="4"></td>
        <td colspan="2">UvIn 134 1.P</td>
        <td colspan="3">Mult 134 3.P -> 137</td>
        <td colspan="6"></td>
    </tr>
    <tr>
        <td>Tuesday</td>
        <td colspan="2">InTe 135 1.P</td>
        <td></td>
        <td colspan="3">MaAn 336 1.P</td>
        <td></td>
        <td colspan="2">AlSu 134 1.P</td>
        <td colspan="2"></td>
        <td colspan="2">AlSu 135 1.P</td>
        <td colspan="2"></td>
    </tr>
    <tr>
        <td>Wednesday</td>
        <td colspan="2"></td>
        <td colspan="3">Kart 134 2.PV</td>
        <td colspan="2">INTE 041 2.PV</td>
        <td></td>
        <td colspan="2">Aj 139 1.P</td>
        <td colspan="5"></td>
    </tr>
    <tr>
        <td>Thursday</td>
        <td colspan="2"></td>
        <td colspan="2">GeIn 139 2.PV</td>
        <td colspan="3">SePr 135 1.P</td>
        <td colspan="8"></td>
    </tr>
    <tr>
        <td>Friday</td>
        <td colspan="15"></td>
    </tr>
</table>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

第二个是.xsl文件-xslt + xsl-fo组合:

<?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" xmlns:a="http://www.w3.org/1999/xhtml">
  <xsl:template match="a:html">
    <fo:root>
      <fo:layout-master-set>
        <fo:simple-page-master master-name="a4">
          <fo:region-body padding-top="1in" padding-left="1.5mm" background-color="#222"/>
        </fo:simple-page-master>
      </fo:layout-master-set>
      <xsl:apply-templates/>
    </fo:root>
  </xsl:template>

  <xsl:template match="a:body">
    <fo:page-sequence master-reference="a4">
      <fo:flow flow-name="xsl-region-body">
        <fo:table>
          <fo:table-body background-color="#333">
            <xsl:for-each select="a:table/a:tr">
              <fo:table-row>
                <xsl:for-each select="a:td">
                  <fo:table-cell padding="0.5mm" border-width="2mm" border-style="outset" border-color="#bbb" color="#aaff00" font-weight="bold" font-family="arial" text-align="center">
                    <xsl:if test="@colspan"><xsl:attribute name="number-columns-spanned"><xsl:value-of select="@colspan"/></xsl:attribute></xsl:if>
                    <xsl:value-of select="."/>
                  </fo:table-cell>
                </xsl:for-each>
              </fo:table-row>
            </xsl:for-each>
          </fo:table-body>
        </fo:table>
      </fo:flow>
    </fo:page-sequence>
  </xsl:template>
</xsl:stylesheet>
Run Code Online (Sandbox Code Playgroud)

Zac*_*ung 5

您将需要一个XSLT处理器,xsltproc它可能已经在Linux发行版中了。然后,您将需要一个处理器来将FO(格式化对象)转换为PDF。Apache具有免费的FO处理器(FOP):Apache™FOP:下载发行版

下载并解压缩FOP后,管道可能如下所示:

$ xsltproc so.xsl so.xml > so.fo
$ <path-to-extracted-fop-dir>/fop so.fo so.pdf
Run Code Online (Sandbox Code Playgroud)

我已经尝试了使用您提供的XML源和XSLT,并且在运行Apache FOP时出现错误。我对您的XSLT一无所知,因此您可能可以解决这些错误。