I am new with Java and I'm trying out some stuffs like generating a PDF I am following the accepted answer of this post I had done everything, slowly but secure.
I am stuck at the last step using ApacheFOP I am almost done but there's an issue I can't fix.
Code:
package calculadoraviajes;
/**
*
* @author Victor
*/
import javax.xml.transform.*;
import java.io.*;
import javax.xml.transform.sax.SAXResult;
import javax.xml.transform.stream.StreamSource;
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.FopFactory;
import org.apache.fop.apps.Fop;
import org.apache.fop.apps.MimeConstants;
public class HowToXSLT {
public static void main(String[] args) throws IOException, TransformerException, FOPException {
try {
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer =
tFactory.newTransformer
(new javax.xml.transform.stream.StreamSource
("howto.xsl"));
transformer.transform
(new javax.xml.transform.stream.StreamSource
("howto.xml"),
new javax.xml.transform.stream.StreamResult
( new FileOutputStream("howto.fo")));
}
catch (Exception e) {
e.printStackTrace( );
}
FopFactory fopFactory = FopFactory.newInstance();
try(OutputStream out = new BufferedOutputStream(new FileOutputStream(new File("exito.pdf")))) {
Fop fop = fopFactory.newFop(MimeConstants.MIME_PDF, out);
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer();
Source src = new StreamSource(new File("howto.fo"));
Result res = new SAXResult(fop.getDefaultHandler());
transformer.transform(src, res);
}
}
}
My problem is here:
FopFactory fopFactory = FopFactory.newInstance();
Seems like I can't leave the newInstance(); parameters empy but following this code example:
Everything should be okay but NetBeans say:
No suitable method found for newInstance(no arguments)
I am kinda sure the error it's in my code or library but to be honest my Java knowledge is totally new.
Thanks so much for your time reading this and probably giving me some light.