I created fop.dll from fop-1.0 using ikvm:
ikvmc -target: library -reference: IKVM.OpenJDK.Core.dll -recurse: {myPathToJars} \ *. jar -version: 1.0 -out: {myPathToJars} \ fop.dll
If I use the fop.dll file in a Windows application, everything works fine.
If I use it in a class library, I get the following error:
"Provider com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl not found" at javax.xml.transform.TransformerFactory.newInstance ()
Code line:
TransformerFactory factory = TransformerFactory.newInstance ();
Here is the method code:
public static void xmlToPDF (String xmlPath, String xslPath, SortedList arguments, String destPdfPath)
{
java.io.File xmlfile = new java.io.File (xmlPath);
java.io.File pdffile = new java.io.File (destPdfPath);
try
{
// configure fopFactory as desired
FopFactory fopFactory = FopFactory.newInstance ();
FOUserAgent foUserAgent = fopFactory.newFOUserAgent ();
// configure foUserAgent as desired
// Setup output
OutputStream outputStream = new java.io.FileOutputStream (pdffile);
outputStream = new java.io.BufferedOutputStream (outputStream);
try
{
// Construct fop with desired output format
Fop fop = fopFactory.newFop ("application / pdf" /*MimeConstants.MIME_PDF*/, foUserAgent, outputStream);
// Setup XSLT
TransformerFactory factory = TransformerFactory.newInstance ();
java.io.File xsltfile = new java.io.File (xslPath);
Transformer transformer = factory.newTransformer (new StreamSource (xsltfile.getAbsoluteFile ()));
// Set the value of a in the stylesheet
if (arguments! = null)
{
IList keys = arguments.GetKeyList ();
foreach (var key in keys)
{
Object value = arguments [key];
transformer.setParameter (key.ToString (), value);
}
}
// Setup input for XSLT transformation
Source src = new StreamSource (xmlfile);
// Resulting SAX events (the generated FO) must be piped through to FOP
Result res = new SAXResult (fop.getDefaultHandler ());
// Start XSLT transformation and FOP processing
transformer.transform (src, res);
}
catch (Exception e1)
{
System.Console.WriteLine (e1.Message);
}
finally
{
outputStream.close ();
}
}
catch (Exception ex)
{
System.Console.WriteLine (ex.Message);
}
}
I used ikvm-0.46.0.1 to create the fop.dll file (based on fop 1.0). I have included the following banks:
avalon-framework-4.2.0.jar
batik-all-1.7.jar
commons-io-1.3.1.jar
commons-logging-1.0.4.jar
fop.jar
serializer-2.7.0.jar
xalan-2.7.0.jar
xercesImpl-2.7.1.jar
xml-apis-1.3.04.jar
xml-apis-ext-1.3.04.jar
xmlgraphics-commons-1.4.jar
Any idea why this error is occurring? Why is the behavior different from a Windows application and class library?
Addendum 10/19/11:
I managed to work as follows:
- MyMainPrg (Windows Forms Application)
- MyFopWrapper (class library calling fop.dll)
But for my case, this is not a solution, because in my target project I have the following structure:
- MainCmdLinePrg (console application, calls DLL_1)
- DLL_1 (calls DLLsharedFop) {there are several DLLs that can call DLLsharedFop}
- DLLsharedFop (calls fop.dll directly or - I don't care - it can call MyFopWrapper)
Unfortunately, this design leads to an error.
You can shorten to a couple (ACmdLinePrg, MyFopWrapper): this does not work already! But (MyMainPrg, MyFopWrapper) does ...