Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using ApacheFOP v1.0 in .NET application

Has anyone successfully complied the Apache FOP v1.0 library to a .NET DLL? I am using the IKVM syntax found at http://onjava.com/pub/a/onjava/2004/08/18/ikvm.html; however, the compiled DLL seems to be incomplete. For example, I cannot instantiate FopFactory object as:

using org.apache.fop.apps;

namespace Utils
{
     public class PdfRender
     {
          public void Render()
          {
            FOUserAgent foUserAgent = fop.getUserAgent();
            FopFactory fopFactory = FopFactory.newInstance();
          }
     }
}
like image 281
Clay Benoit Avatar asked Oct 18 '10 17:10

Clay Benoit


People also ask

What is use of Apache FOP?

Apache™ FOP It is a Java application that reads a formatting object (FO) tree and renders the resulting pages to a specified output. Output formats currently supported include PDF, PS, PCL, AFP, XML (area tree representation), Print, AWT and PNG, and to a lesser extent, RTF and TXT. The primary output target is PDF.

What is Apache FOP Version?

FOP is open source software, and is distributed under the Apache License 2.0.

Is Apache FOP thread safe?

Multithreading FOP FOP is not currently completely thread safe.


1 Answers

I know this is an old thread but it still took some research to get this working. It is now available with NuGet in Visual Studio 2013. The NuGet package is called crispin.fop. In my code below, I pass in an "fop" file and the new PDF file I want created and "voila", it is created.

    using org.apache.fop.tools;
    using org.apache.fop.apps;
    using org.xml.sax;
    using java.io;

    public void GeneratePDF(string foFile, string pdfFile)
    {
        OutputStream os = new BufferedOutputStream(new FileOutputStream(new java.io.File(pdfFile)));

        try
        {
            FopFactory fopFactory = FopFactory.newInstance();
            Fop fop = fopFactory.newFop("application/pdf", os);
            FOUserAgent foUserAgent = fop.getUserAgent();
            javax.xml.transform.TransformerFactory factory = javax.xml.transform.TransformerFactory.newInstance();
            javax.xml.transform.Transformer transformer = factory.newTransformer();
            javax.xml.transform.Source src = new javax.xml.transform.stream.StreamSource(new java.io.File(foFile));
            javax.xml.transform.Result res = new javax.xml.transform.sax.SAXResult(fop.getDefaultHandler());
            transformer.transform(src, res);
        }

        catch (Exception ex)
        {                
            throw ex;
        }

        finally
        {
            os.close();
        }
    }
like image 174
user3155037 Avatar answered Sep 20 '22 07:09

user3155037