• 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

Strange FOP behaviour

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi! Can someone please tell me what I'm doing wrong?
I have an XML file and an XSL file (to convert the XML to FO). I executed the commandline version of FOP (fop.bat) as follows:
fop -xml myXML.xml -xsl myXSL.xsl -pdf myPDF.pdf
This works perfectly and the PDF was generated properly. However, when I embed the following code (example from FOP webpage) in my program I'm getting a NullPointerException:
Driver driver = new Driver();
driver.setRenderer(Driver.RENDER_PDF);
InputHandler inputHandler = new XSLTInputHandler(xmlFile, xslFile);
XMLReader parser = inputHandler.getParser();
driver.setOutputStream(new FileOutputStream(outFile));
driver.render(parser, InputHandler.getInputSource());
In addition, I used Xalan to manually convert the XML file to FO and use the other example from the FOP webpage:
Driver driver = new Driver();
driver.setRenderer(Driver.RENDER_PDF);
driver.setInputSource(new FileInputSource(args[0]));
driver.setOutputStream(new FileOutputStream(args[1]));
driver.run();
This code works perfectly and the PDF was rendered properly. According to FOP FAQ, there must be something wrong in my XSL file or XML file thus it is causing the NullPointerException. However, if this was the case then all attempts should have failed or am I missing something here? Any enlightenment would be greatly appreciated. Thanks.
 
author and deputy
Posts: 3150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If your above code is not working you can try the below code..

This is working fine for me provided i have vaild xsl and xml.
 
Balaji Loganathan
author and deputy
Posts: 3150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Philip Hung:
Driver driver = new Driver();
driver.setRenderer(Driver.RENDER_PDF);
InputHandler inputHandler = new XSLTInputHandler(xmlFile, xslFile);
XMLReader parser = inputHandler.getParser();
driver.setOutputStream(new FileOutputStream(outFile));
driver.render(parser, InputHandler.getInputSource());


Or else you can set the driver.setOutputStream to
something like
ByteArrayOutputStream out = new ByteArrayOutputStream();
driver.setOutputStream(out);
and convert this out to bytearray and write to a file.
 
Philip Hung
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks. Your sugggestion worked perfectly.
 
The world's cheapest jedi mind trick: "Aw c'mon, why not read this tiny ad?"
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic