D
DomeTheDon
Hallo,
ich habe ein Problem mit Apache Fop, speziell mit der FopFactory-Instanzierung. Mein Programm soll eine xml-datei als pdf darstellen. Es wirft auch keinen Fehler, aber es macht einfach nix. Hier mein Code, ich habe ihn aus der ExampleXML2PDF übernommen.
Ich verwenden die Version 0.95beta.
Das Programm läuft nur bis zur rot markierten Stelle, die FopFactory selbst wird nicht instanziert. Ich weiß nicht wo der Fehler liegen könnte^^
Im Classpath habe ich als Referenced Libraries:
-Avalon-Framework-4.2.0
-Batik-All-1.7
-Commons-IO-1.3.1
-Commons-Logging-1.0.4
-Fop.jar
-Serializer-2.7.0
-Xalan-2.7.0
-XercesImpl-2.7.1
-xml-apis-1.3.02
-xml-apis-ext
-xml-graphics-commons-1.3
Ich hoffe ihr könnt mir helfen, ich bin nämlich am verzweifeln.
MfG Dominik
ich habe ein Problem mit Apache Fop, speziell mit der FopFactory-Instanzierung. Mein Programm soll eine xml-datei als pdf darstellen. Es wirft auch keinen Fehler, aber es macht einfach nix. Hier mein Code, ich habe ihn aus der ExampleXML2PDF übernommen.
Ich verwenden die Version 0.95beta.
Code:
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.sax.SAXResult;
import javax.xml.transform.stream.StreamSource;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.apps.Fop;
import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.MimeConstants;
//Java
/**
* This class demonstrates the conversion of an XML file to PDF using
* JAXP (XSLT) and FOP (XSL-FO).
*/
public class ExampleXML2PDF {
/**
* Main method.
* @param args command-line arguments
*/
// static private FopFactory flopFactory = FopFactory.newInstance();
public void convert() {
try {
System.out.println("FOP ExampleXML2PDF\n");
System.out.println("Preparing...");
// Setup directories
File baseDir = new File("C:/TESTxsl/");
File outDir = new File(baseDir, "out");
outDir.mkdirs();
// Setup input and output files
File xmlfile = new File(baseDir, "xslfoRef.xml");
File xsltfile = new File(baseDir, "xml2pdf.xsl");
File pdffile = new File(outDir, "ResultXML2PDF.pdf");
System.out.println("Input: XML (" + xmlfile + ")");
System.out.println("Stylesheebob: " + xsltfile);
System.out.println("Output: PDF (" + pdffile + ")");
System.out.println();
System.out.println("Transforming...");
// configure fopFactory as desired
FopFactory flopFactory = FopFactory.newInstance();
FOUserAgent foUserAgent = flopFactory.newFOUserAgent();
// configure foUserAgent as desired
// Setup output
OutputStream out = new FileOutputStream(pdffile);
out = new BufferedOutputStream(out);
try {
// Construct fop with desired output format
Fop fop = flopFactory.newFop(MimeConstants.MIME_PDF, foUserAgent, out);
// Setup XSLT
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(new StreamSource(xsltfile));
// Set the value of a <param> in the stylesheet
transformer.setParameter("versionParam", "2.0");
// Setup input for XSLT transformation
Source src = new StreamSource(xmlfile);
// Resulting SAX events (the generated FO) must be piped through to FOP
Result res = new SAXResult(fop.getDefaultHandler());
// Start XSLT transformation and FOP processing
transformer.transform(src, res);
} finally {
out.close();
}
System.out.println("Success!");
} catch (Exception e) {
System.out.println(e.toString());
e.printStackTrace(System.err);
System.exit(-1);
}
}
}
Das Programm läuft nur bis zur rot markierten Stelle, die FopFactory selbst wird nicht instanziert. Ich weiß nicht wo der Fehler liegen könnte^^
Im Classpath habe ich als Referenced Libraries:
-Avalon-Framework-4.2.0
-Batik-All-1.7
-Commons-IO-1.3.1
-Commons-Logging-1.0.4
-Fop.jar
-Serializer-2.7.0
-Xalan-2.7.0
-XercesImpl-2.7.1
-xml-apis-1.3.02
-xml-apis-ext
-xml-graphics-commons-1.3
Ich hoffe ihr könnt mir helfen, ich bin nämlich am verzweifeln.
MfG Dominik