error create pdf from fo files

  • Thread starter Ordinamento per chiave Hashtable
  • Start date
O

Ordinamento per chiave Hashtable

Hi,
I'm developing a web application with jsf.
I developed a java class which creates a pdf file from a xml file using
fop.
This class includes the main method and it work very well, that is it
generates the fo and pdf files.
This code included into my web application (I've changed the main
method) generates the fo file but not the pdf file.
Have you any ideas?
Thanks advance.


This is the main changed:

public void xmltopdf() {
try {
File xmlfile = new File("file.xml");
File xsltfile = new File("xhtml-to-xslfo.xsl");
File fofile = new File("Result.fo");
File pdffile = new File("Result.pdf");

xml2pdf app = new xml2pdf();
app.convertXML2FO(xmlfile, xsltfile, fofile);

xml2pdf app1 = new xml2pdf();
app1.convertFO2PDF(fofile,pdffile);

} catch (Exception e) {
e.printStackTrace(System.err);
}
}

This is the method which should create pdf file:
public void convertFO2PDF(File fo, File pdf) throws IOException,
FOPException {

OutputStream out = null;

try {
Driver driver = new Driver();
Logger logger = new
ConsoleLogger(ConsoleLogger.LEVEL_INFO);
driver.setLogger(logger);
driver.setRenderer(Driver.RENDER_PDF);

out = new FileOutputStream(pdf);
out = new BufferedOutputStream(out);
driver.setOutputStream(out);

// Setup JAXP using identity transformer
TransformerFactory factory =
TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer();

// Setup input stream
Source src = new StreamSource(fo);

// Resulting SAX events (the generated FO) must be piped
through to FOP
Result res = new SAXResult(driver.getContentHandler());

// Start XSLT transformation and FOP processing
transformer.transform(src, res);

} catch (Exception e) {
e.printStackTrace(System.err);
System.exit(-1);
} finally {
out.close();
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top