Apache FOP the method newInstance(FopFactoryConfig) in the type FopFactory is not applicable for the arguments () -


i getting following error:

exception in thread "main" java.lang.error: unresolved compilation problem:     method newinstance(fopfactoryconfig) in type fopfactory not applicable arguments ()      @ fopdemo.fopvass.pdfhandler.createpdffile(pdfhandler.java:42)     @ fopdemo.fopvass.testpdf.main(testpdf.java:40) 

this code:

package fopdemo.fopvass;  import java.io.bytearrayinputstream; import java.io.bytearrayoutputstream; import java.io.file; import java.io.fileoutputstream; import java.io.ioexception; import java.io.outputstream; import java.net.url;  import javax.xml.bind.jaxbcontext; import javax.xml.bind.jaxbexception; import javax.xml.bind.marshaller; import javax.xml.transform.result; import javax.xml.transform.source; import javax.xml.transform.transformer; import javax.xml.transform.transformerconfigurationexception; import javax.xml.transform.transformerexception; import javax.xml.transform.transformerfactory; import javax.xml.transform.transformerfactoryconfigurationerror; import javax.xml.transform.dom.domresult; import javax.xml.transform.dom.domsource; import javax.xml.transform.sax.saxresult; import javax.xml.transform.stream.streamsource;  import org.apache.fop.apps.fopexception; import org.apache.fop.apps.fouseragent; import org.apache.fop.apps.fop; import org.apache.fop.apps.fopfactory; import org.apache.fop.apps.mimeconstants;  public class pdfhandler {     public static final string extension = ".pdf";     public string prescription_url = "template.xsl";      public string createpdffile(bytearrayoutputstream xmlsource, string templatefilepath) throws ioexception {         file file = file.createtempfile("" + system.currenttimemillis(), extension);         url url = new file(templatefilepath + prescription_url).touri().tourl();         // creation of transform source         streamsource transformsource = new streamsource(url.openstream());         // create instance of fop factory         fopfactory fopfactory = fopfactory.newinstance();         // user agent needed transformation         fouseragent fouseragent = fopfactory.newfouseragent();         // store output         bytearrayoutputstream pdfoutstream = new bytearrayoutputstream();         streamsource source = new streamsource(new bytearrayinputstream(xmlsource.tobytearray()));         transformer xslfotransformer;         try {             transformerfactory transfact = transformerfactory.newinstance();              xslfotransformer = transfact.newtransformer(transformsource);             // construct fop desired output format             fop fop;             try {                 fop = fopfactory.newfop(mimeconstants.mime_pdf, fouseragent, pdfoutstream);                 // resulting sax events (the generated fo)                 // must piped through fop                 result res = new saxresult(fop.getdefaulthandler());                  // start xslt transformation , fop processing                 try {                     // happen here..                     xslfotransformer.transform(source, res);                      // if want save pdf file use following code                     outputstream out = new java.io.fileoutputstream(file);                     out = new java.io.bufferedoutputstream(out);                     fileoutputstream str = new fileoutputstream(file);                     str.write(pdfoutstream.tobytearray());                     str.close();                     out.close();                  } catch (transformerexception e) {                     e.printstacktrace();                 }             } catch (fopexception e) {                 e.printstacktrace();             }         } catch (transformerconfigurationexception e) {             e.printstacktrace();         } catch (transformerfactoryconfigurationerror e) {             e.printstacktrace();         }         return file.getpath();     }      public bytearrayoutputstream getxmlsource(employeedata data) throws exception {         jaxbcontext context;          bytearrayoutputstream outstream = new bytearrayoutputstream();          try {             context = jaxbcontext.newinstance(employeedata.class);             marshaller m = context.createmarshaller();             m.setproperty(marshaller.jaxb_formatted_output, boolean.true);             m.marshal(data, system.out);             m.marshal(data, outstream);         } catch (jaxbexception e) {              e.printstacktrace();         }         return outstream;      } } 

this called:

package fopdemo.fopvass;  import java.io.bytearrayoutputstream; import java.util.arraylist; /**  * @author debasmita.sahoo  *  */ public class testpdf {     public static void main(string args[]){         system.out.println("hi testing");         arraylist employeelist = new arraylist();         string templatefilepath ="c:/paula/proyectos/fop/fopvass/resources/";          employee e1= new employee();         e1.setname("debasmita1 sahoo");         e1.setemployeeid("10001");         e1.setaddress("pune");         employeelist.add(e1);          employee e2= new employee();         e2.setname("debasmita2 sahoo");         e2.setemployeeid("10002");         e2.setaddress("test");         employeelist.add(e2);          employee e3= new employee();         e3.setname("debasmita3 sahoo");         e3.setemployeeid("10003");         e3.setaddress("mumbai");         employeelist.add(e3);          employeedata data = new employeedata();         data.seteemployeelist(employeelist);         pdfhandler handler = new pdfhandler();          try {             bytearrayoutputstream streamsource = handler.getxmlsource(data);              handler.createpdffile(streamsource,templatefilepath);         } catch (exception e) {             // todo auto-generated catch block             e.printstacktrace();         }     } } 

this problem:

fopfactory fopfactory = fopfactory.newinstance(); 

if @ code method, newinstance(), takes parameter. need supply parameter.

from documentation (provided mathias muller), under 'basic usage':

fopfactory fopfactory = fopfactory.newinstance(new file("c:/temp/fop.xconf")); 

you need provide file object.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

android - Keyboard hides my half of edit-text and button below it even in scroll view -