Hallo zusammen ,
ich versuche gerade mit FOP-1.0 Daten aus einer mySql-Datenbank in einem PDF zu speichern.
Dazu habe ich mich bis jetzt sehr an den FOP-Beispielen von Apache(die beim Download enthalten sind) orientiert. Das erzeugen des XML-Files funktioniert ohne Probleme, auch beim erzeugen des FO-Files gibt es keine Warnings oder Errors.
Beim erzeugen des PDFs kommt es aber zur folgenden Fehlermeldung: Content is not allowed in prolog.
Der Grund dafür ist ,dass die FO-Datei folgender maßen aussieht:
[XML]<?xml version="1.0" encoding="UTF-8"?>2012-02-10 10:57:04.02402.121000.0221.022012-02-10 10:57:05.02412.121000. ..... 0.0221.02[/XML]
Die Klasse die diese Datei erzeugt ist 1:1 die aus dem Beispielen :
Die verwendete xml-Datei wurde in einer Zeile erzeugt, ich habe sie aber zu besseren Lesbarkeit aber ein bisschen formatiert:
[XML]<?xml version="1.0" encoding="UTF-8"?>
<MWs>
<MW>
<time>2012-02-10 10:57:04.0</time><gw_ID>2</gw_ID><ID>40</ID>
<U><Spannung>2.1</Spannung><Status>2</Status></U><dc><Drehzahl>1000.0</Drehzahl><Status>2</Status></dc><t><Temperatur>21.0</Temperatur><Status>2</Status></t>
</MW><MW>
<time>2012-02-10 10:57:05.0</time><gw_ID>2</gw_ID><ID>41</ID>
<U><Spannung>2.1</Spannung><Status>2</Status></U><dc><Drehzahl>1000.0</Drehzahl><Status>2</Status></dc><t><Temperatur>21.0</Temperatur><Status>2</Status></t>
</MW><MW>
<time>2012-02-10 10:57:06.0</time><gw_ID>2</gw_ID><ID>42</ID>
<U><Spannung>2.1</Spannung><Status>2</Status></U><dc><Drehzahl>1000.0</Drehzahl><Status>2</Status></dc><t><Temperatur>20.5</Temperatur><Status>2</Status></t>
</MW><MW>
<time>2012-02-10 10:57:08.0</time><gw_ID>2</gw_ID><ID>43</ID>
<U><Spannung>2.1</Spannung><Status>2</Status></U><dc><Drehzahl>1000.0</Drehzahl><Status>2</Status></dc><t><Temperatur>20.5</Temperatur><Status>2</Status></t>
</MW><MW><time>2012-02-10 10:57:09.0</time><gw_ID>2</gw_ID><ID>44</ID>
<U><Spannung>2.1</Spannung><Status>2</Status></U><dc><Drehzahl>1000.0</Drehzahl><Status>2</Status></dc><t><Temperatur>21.0</Temperatur><Status>2</Status></t>
</MW><MW>
<time>2012-02-10 10:57:10.0</time><gw_ID>2</gw_ID><ID>45</ID>
<U><Spannung>2.1</Spannung><Status>2</Status></U><dc><Drehzahl>1000.0</Drehzahl><Status>2</Status></dc><t><Temperatur>21.0</Temperatur><Status>2</Status></t>
</MW>
</MWs>[/XML]
Und zum Schluss noch die XSL-Datei:
[XML]
<?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">
<fo:root>
<fo:layout-master-set>
</fo:layout-master-set>
<foage-sequence master-reference="CoverPage">
<fo:flow flow-name="xsl-region-body">
<fo:block>
<fo:table height="100%" width="100%" border="1.5mm double black" block-progression-dimension="auto" table-layout="auto">
<fo:table-column column-width="1.6cm" />
<fo:table-column column-width="1.3cm" />
<fo:table-column column-width="1.3cm" />
<fo:table-column column-width="1.6cm" />
<fo:table-column column-width="1.6cm" />
<fo:table-column column-width="1.6cm" />
<!-- HEADER -->
<fo:table-header>
<fo:table-row>
<fo:table-cell number-columns-spanned="1" border-right="0.5mm solid black" border-bottom="1mm solid black">
<fo:block >Time</fo:block></fo:table-cell>
<fo:table-cell number-columns-spanned="1" border-right="0.5mm solid black" border-bottom="1mm solid black"><fo:block >ID</fo:block></fo:table-cell>
<fo:table-cell number-columns-spanned="1" border-right="0.5mm solid black" border-bottom="1mm solid black"><fo:block >gw_ID</fo:block></fo:table-cell>
<fo:table-cell number-columns-spanned="1" border-right="0.5mm solid black" border-bottom="1mm solid black"><fo:block >Spannung</fo:block></fo:table-cell>
<fo:table-cell number-columns-spanned="1" border-right="0.5mm solid black" border-bottom="1mm solid black"><fo:block >Drehzahl</fo:block></fo:table-cell>
<fo:table-cell number-columns-spanned="1" border-right="0.5mm solid black" border-bottom="1mm solid black"><fo:block >Temperatur</fo:block></fo:table-cell>
</fo:table-row>
</fo:table-header>
<fo:table-body>
<xsl:for-each select="MWs/MW"><fo:table-row>
<fo:table-cell number-columns-spanned="1" border-right="0.5mm solid black" border-bottom="1mm solid black">
<fo:block><xsl:value-of select="time" /></fo:block></fo:table-cell>
<fo:table-cell number-columns-spanned="1" border-right="0.5mm solid black" border-bottom="1mm solid black">
<fo:block ><xsl:value-of select="ID" /></fo:block></fo:table-cell>
<fo:table-cell number-columns-spanned="1" border-right="0.5mm solid black" border-bottom="1mm solid black">
<fo:block><xsl:value-of select="gw_ID" /></fo:block></fo:table-cell>
<fo:table-cell number-columns-spanned="1" border-right="0.5mm solid black" border-bottom="1mm solid black">
<xsl:choose>
<xsl:when test="U/Status='2'"><fo:block background-color="red"><xsl:value-of select="U/Spannung" /></fo:block></xsl:when>
<xsl:when test="U/Status='1'"><fo:block background-color="yellow"><xsl:value-of select="U/Spannung" /></fo:block></xsl:when>
<xsltherwise><fo:block><xsl:value-of select="U/Spannung" /></fo:block></xsltherwise>
</xsl:choose>
</fo:table-cell>
<fo:table-cell number-columns-spanned="1" border-right="0.5mm solid black" border-bottom="1mm solid black">
<xsl:choose>
<xsl:when test="dc/Status='2'"><fo:block background-color="red"><xsl:value-of select="dc/Drezahl" /></fo:block></xsl:when>
<xsl:when test="dc/Status='1'"><fo:block background-color="yellow"><xsl:value-of select="dc/Drezahl" /></fo:block></xsl:when>
<xsltherwise><fo:block><xsl:value-of select="dc/Drezahl" /></fo:block></xsltherwise>
</xsl:choose>
</fo:table-cell>
<fo:table-cell number-columns-spanned="1" border-right="0.5mm solid black" border-bottom="1mm solid black">
<xsl:choose>
<xsl:when test="t/Status='2'"><fo:block background-color="red"><xsl:value-of select="t/Temperatur" /></fo:block></xsl:when>
<xsl:when test="t/Status='1'"><fo:block background-color="yellow"><xsl:value-of select="t/Temperatur" /></fo:block></xsl:when>
<xsltherwise><fo:block><xsl:value-of select="t/Temperatur" /></fo:block></xsltherwise>
</xsl:choose>
</fo:table-cell>
</fo:table-row>
</xsl:for-each>
</fo:table-body></fo:table></fo:block>
</fo:flow>
</foage-sequence>
</fo:root>
</xsl:stylesheet>
[/XML]
Ich hoffe von euch hat jemand eine Idee, woran das liegen könnte. Es ist nämlich das erste Mal, dass ich FOB benutze und ich bin gerade ziemlich ratlos.
Bin für jede Hilfe dankbar.
ich versuche gerade mit FOP-1.0 Daten aus einer mySql-Datenbank in einem PDF zu speichern.
Dazu habe ich mich bis jetzt sehr an den FOP-Beispielen von Apache(die beim Download enthalten sind) orientiert. Das erzeugen des XML-Files funktioniert ohne Probleme, auch beim erzeugen des FO-Files gibt es keine Warnings oder Errors.
Beim erzeugen des PDFs kommt es aber zur folgenden Fehlermeldung: Content is not allowed in prolog.
Der Grund dafür ist ,dass die FO-Datei folgender maßen aussieht:
[XML]<?xml version="1.0" encoding="UTF-8"?>2012-02-10 10:57:04.02402.121000.0221.022012-02-10 10:57:05.02412.121000. ..... 0.0221.02[/XML]
Die Klasse die diese Datei erzeugt ist 1:1 die aus dem Beispielen :
Java:
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
public class XML2FO {
public void convertXML2FO(File xml, File xslt, File fo)
throws IOException, TransformerException {
//Setup output
OutputStream out = new java.io.FileOutputStream(fo);
try {
//Setup XSLT
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(new StreamSource(xslt));
//Setup input for XSLT transformation
Source src = new StreamSource(xml);
//Resulting SAX events (the generated FO) must be piped through to FOP
Result res = new StreamResult(out);
//Start XSLT transformation and FOP processing
transformer.transform(src, res);
} finally {
out.close();
}
}
}
[XML]<?xml version="1.0" encoding="UTF-8"?>
<MWs>
<MW>
<time>2012-02-10 10:57:04.0</time><gw_ID>2</gw_ID><ID>40</ID>
<U><Spannung>2.1</Spannung><Status>2</Status></U><dc><Drehzahl>1000.0</Drehzahl><Status>2</Status></dc><t><Temperatur>21.0</Temperatur><Status>2</Status></t>
</MW><MW>
<time>2012-02-10 10:57:05.0</time><gw_ID>2</gw_ID><ID>41</ID>
<U><Spannung>2.1</Spannung><Status>2</Status></U><dc><Drehzahl>1000.0</Drehzahl><Status>2</Status></dc><t><Temperatur>21.0</Temperatur><Status>2</Status></t>
</MW><MW>
<time>2012-02-10 10:57:06.0</time><gw_ID>2</gw_ID><ID>42</ID>
<U><Spannung>2.1</Spannung><Status>2</Status></U><dc><Drehzahl>1000.0</Drehzahl><Status>2</Status></dc><t><Temperatur>20.5</Temperatur><Status>2</Status></t>
</MW><MW>
<time>2012-02-10 10:57:08.0</time><gw_ID>2</gw_ID><ID>43</ID>
<U><Spannung>2.1</Spannung><Status>2</Status></U><dc><Drehzahl>1000.0</Drehzahl><Status>2</Status></dc><t><Temperatur>20.5</Temperatur><Status>2</Status></t>
</MW><MW><time>2012-02-10 10:57:09.0</time><gw_ID>2</gw_ID><ID>44</ID>
<U><Spannung>2.1</Spannung><Status>2</Status></U><dc><Drehzahl>1000.0</Drehzahl><Status>2</Status></dc><t><Temperatur>21.0</Temperatur><Status>2</Status></t>
</MW><MW>
<time>2012-02-10 10:57:10.0</time><gw_ID>2</gw_ID><ID>45</ID>
<U><Spannung>2.1</Spannung><Status>2</Status></U><dc><Drehzahl>1000.0</Drehzahl><Status>2</Status></dc><t><Temperatur>21.0</Temperatur><Status>2</Status></t>
</MW>
</MWs>[/XML]
Und zum Schluss noch die XSL-Datei:
[XML]
<?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">
<fo:root>
<fo:layout-master-set>
</fo:layout-master-set>
<foage-sequence master-reference="CoverPage">
<fo:flow flow-name="xsl-region-body">
<fo:block>
<fo:table height="100%" width="100%" border="1.5mm double black" block-progression-dimension="auto" table-layout="auto">
<fo:table-column column-width="1.6cm" />
<fo:table-column column-width="1.3cm" />
<fo:table-column column-width="1.3cm" />
<fo:table-column column-width="1.6cm" />
<fo:table-column column-width="1.6cm" />
<fo:table-column column-width="1.6cm" />
<!-- HEADER -->
<fo:table-header>
<fo:table-row>
<fo:table-cell number-columns-spanned="1" border-right="0.5mm solid black" border-bottom="1mm solid black">
<fo:block >Time</fo:block></fo:table-cell>
<fo:table-cell number-columns-spanned="1" border-right="0.5mm solid black" border-bottom="1mm solid black"><fo:block >ID</fo:block></fo:table-cell>
<fo:table-cell number-columns-spanned="1" border-right="0.5mm solid black" border-bottom="1mm solid black"><fo:block >gw_ID</fo:block></fo:table-cell>
<fo:table-cell number-columns-spanned="1" border-right="0.5mm solid black" border-bottom="1mm solid black"><fo:block >Spannung</fo:block></fo:table-cell>
<fo:table-cell number-columns-spanned="1" border-right="0.5mm solid black" border-bottom="1mm solid black"><fo:block >Drehzahl</fo:block></fo:table-cell>
<fo:table-cell number-columns-spanned="1" border-right="0.5mm solid black" border-bottom="1mm solid black"><fo:block >Temperatur</fo:block></fo:table-cell>
</fo:table-row>
</fo:table-header>
<fo:table-body>
<xsl:for-each select="MWs/MW"><fo:table-row>
<fo:table-cell number-columns-spanned="1" border-right="0.5mm solid black" border-bottom="1mm solid black">
<fo:block><xsl:value-of select="time" /></fo:block></fo:table-cell>
<fo:table-cell number-columns-spanned="1" border-right="0.5mm solid black" border-bottom="1mm solid black">
<fo:block ><xsl:value-of select="ID" /></fo:block></fo:table-cell>
<fo:table-cell number-columns-spanned="1" border-right="0.5mm solid black" border-bottom="1mm solid black">
<fo:block><xsl:value-of select="gw_ID" /></fo:block></fo:table-cell>
<fo:table-cell number-columns-spanned="1" border-right="0.5mm solid black" border-bottom="1mm solid black">
<xsl:choose>
<xsl:when test="U/Status='2'"><fo:block background-color="red"><xsl:value-of select="U/Spannung" /></fo:block></xsl:when>
<xsl:when test="U/Status='1'"><fo:block background-color="yellow"><xsl:value-of select="U/Spannung" /></fo:block></xsl:when>
<xsltherwise><fo:block><xsl:value-of select="U/Spannung" /></fo:block></xsltherwise>
</xsl:choose>
</fo:table-cell>
<fo:table-cell number-columns-spanned="1" border-right="0.5mm solid black" border-bottom="1mm solid black">
<xsl:choose>
<xsl:when test="dc/Status='2'"><fo:block background-color="red"><xsl:value-of select="dc/Drezahl" /></fo:block></xsl:when>
<xsl:when test="dc/Status='1'"><fo:block background-color="yellow"><xsl:value-of select="dc/Drezahl" /></fo:block></xsl:when>
<xsltherwise><fo:block><xsl:value-of select="dc/Drezahl" /></fo:block></xsltherwise>
</xsl:choose>
</fo:table-cell>
<fo:table-cell number-columns-spanned="1" border-right="0.5mm solid black" border-bottom="1mm solid black">
<xsl:choose>
<xsl:when test="t/Status='2'"><fo:block background-color="red"><xsl:value-of select="t/Temperatur" /></fo:block></xsl:when>
<xsl:when test="t/Status='1'"><fo:block background-color="yellow"><xsl:value-of select="t/Temperatur" /></fo:block></xsl:when>
<xsltherwise><fo:block><xsl:value-of select="t/Temperatur" /></fo:block></xsltherwise>
</xsl:choose>
</fo:table-cell>
</fo:table-row>
</xsl:for-each>
</fo:table-body></fo:table></fo:block>
</fo:flow>
</foage-sequence>
</fo:root>
</xsl:stylesheet>
[/XML]
Ich hoffe von euch hat jemand eine Idee, woran das liegen könnte. Es ist nämlich das erste Mal, dass ich FOB benutze und ich bin gerade ziemlich ratlos.
Bin für jede Hilfe dankbar.