• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Please help: Transformer Exception while applying transformation.

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
; Line#: -1; Column#: -1
javax.xml.transform.TransformerException: Premature end of file.

Hello,

I am using FOP to convert an xml using an xslt to PDF. I use the following code. I pass an xml file converted as source and an DataHandler xslt)

>>>>>>>>>>>>>>>>
public File convertXML2PDF(javax.xml.transform.Source xml, javax.activation.DataHandler xslt)
throws IOException, FOPException, TransformerException {
//create a pdf file to return
File pcl = new File("ReturnPcl.pdf");
//Construct driver
Driver driver = new Driver();

//Setup logger
Logger logger = new ConsoleLogger(ConsoleLogger.LEVEL_INFO);
driver.setLogger(logger);
MessageHandler.setScreenLogger(logger);

//Setup Renderer (output format)
driver.setRenderer(Driver.RENDER_PDF);

//Setup output

OutputStream out = new java.io.FileOutputStream(pcl);
try {
driver.setOutputStream(out);

//convert data handler to streamsource

TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(new StreamSource(xslt.getInputStream()));

out.flush();
//Resulting SAX events (the generated FO) must be piped through to FOP

Result res = new SAXResult(driver.getContentHandler());


System.out.println("just before teh tranform");
//Start XSLT transformation and FOP processing

transformer.transform(xml, res);

out.flush();

}catch(IOException ioe){
System.out.println(ioe.getMessage());
}catch(TransformerException te){
te.printStackTrace();
} finally {
out.close();
}
return pcl;
}

>>>>>>>>>>>>>>>>>>>>>>>>>
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is what I would do -

Get the input XML file. Run it through the FOP and debug the style sheet using the FOP commandline options.

- m
 
reply
    Bookmark Topic Watch Topic
  • New Topic