[inhalt]
Projekt BISO 3 - Handbuch

Beispiel Erzeugen eines PDF via Smarty/FOP

XSL-Stylesheet (z.B. standard_a4.xsl)

<!-- Definiert eine simple A4-Seite -->
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:fo="http://www.w3.org/1999/XSL/Format"
                version='1.0'>

<xsl:output encoding="ISO-8859-1" method="xml"/>
<xsl:attribute-set name="inside-table">
  <xsl:attribute name="start-indent">0pt</xsl:attribute>
  <xsl:attribute name="text-align">start</xsl:attribute>
    <xsl:attribute name="font-size">11pt</xsl:attribute>
    <xsl:attribute name="font-family">Arial</xsl:attribute>
    <xsl:attribute name="line-height">13pt</xsl:attribute>
</xsl:attribute-set>


<xsl:template match="/">
  <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<!-- LAYOUT-MASTER-SET -->
        <fo:layout-master-set>
<!-- SIMPLE-PAGE-MASTER -->
            <fo:simple-page-master master-name="A4"
                 page-width="210mm"  page-height="297mm"
                 margin-top="20mm"  margin-bottom="20mm"
                 margin-left="20mm" margin-right="20mm">
                <fo:region-body/>
            </fo:simple-page-master>
        </fo:layout-master-set>
<!-- PAGE-SEQUENCE -->
    <fo:page-sequence master-reference="A4">
<!-- BODY -->
            <fo:flow flow-name="xsl-region-body">
                    <xsl:apply-templates select="doc"/>
            </fo:flow>
        </fo:page-sequence>
    </fo:root>
</xsl:template>
<xsl:include href="basis_templates.xsl"/>
</xsl:stylesheet>

Notiz: Aus Platzgründen wird die zusätzlich inkludierte Vorlage basis_templates.xsl nicht mit eingeblendet. Darin sind die grundsätzlichen Dokument-Elemente für das XML definiert und in jeder Falladmin-Instanz vorhanden.

XML-Template für Smarty

<doc>
  <Inhalt>
    <a>Hallo, {$person.vorname}, heute ist der {$datum}.</a>
  </Inhalt>
</doc>

Script, um das PDF zu erzeugen:

// Zusammenstellen der Input-Daten für das XML-Template
$person = array('name'=>'Schenkel', 'vorname'=>'Alexander');
$datum = date('d.m.Y');

// Zuweisen der Daten an Smarty:
$smarty = new Smarty();
$smarty->assign('person', $person);
$smarty->assign('datum', $datum);

// Das XML-Template via Smarty ausfüllen und speichern:
file_put_contents('output.xml', $smarty->fetch('xml_template.xml');

// FOP ausführen, PDF wird erzeugt:
$fop = new FOPExecutor('output.xml', 'standard_a4.xsl', 'my_pdf.pdf');
$ret = $fop->exec();