This is an follow-up comment to the article IKVM, which describes 'calling Apache FOP from C# or VB.NET'.
Just some additional comments.
1.Along with other steps specified in the article, while compiling fop.jar into .NET assembley, dont forget to add reference to the .dll file avalon-framework-cvs-20020806.dll, otherwise you will get an error saying
java.lang.NoClassDefFoundError: org.apache.avalon.framework.logger.ConsoleLogger .
ikvmc -target:library
-reference:IKVM.GNU.Classpath.dll -reference:xml-apis.dll
-reference:batik.dll -reference:avalon-framework-cvs-20020806.dll
fop.jar
2. Atleast in my PC, the fop.jar file from apache site itself is working fine. You dont need to download the patched fop.jar
3. Calling Apache FOP from C# web application
This is a sample code snippet which shows how to call Apache FOP from C#.NET, the below code will convert a XML file to PDF. The xml file is an pre generated xsl:fo file.
using org.apache.fop.apps;
using ikvm.lang;
...
private void Page_Load(object sender, System.EventArgs e)
{
try{
//Put user code to initialize the page here
//Load assemblies that are not directly
//referenced since no CLASSPATH is defined
AppDomain.CurrentDomain.Load("xercesImpl-2.2.1");
AppDomain.CurrentDomain.Load("batik");
java.lang.System.setProperty("javax.xml.parsers.SAXParserFactory","org.apache.xerces.jaxp.SAXParserFactoryImpl");
java.io.ByteArrayOutputStream bArrayOS = new java.io.ByteArrayOutputStream();
// specify the .fo file location (relative or absolute)
org.xml.sax.InputSource isrc = new org.xml.sax.InputSource("/files/xslt/sample.fo");
Driver driver = new Driver(isrc, bArrayOS);
driver.setLogger(log);
driver.setRenderer(Driver.RENDER_PDF);
driver.run();
bArrayOS.close();
byte[] bArray = bArrayOS.toByteArray();
Response.ClearHeaders();
Response.Clear();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;
filename=foo.pdf");
Response.Flush();
Response.BinaryWrite(bArray);
Response.End();
}catch(Exception ex){ Response.Write(ex.ToString());}
}
Anyway a C# port for Apache FOP would be much better for debugging purpose.
