Using ApacheFOP v1.0 in .NET application

前端 未结 5 1357
闹比i
闹比i 2020-12-28 10:03

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

5条回答
  •  失恋的感觉
    2020-12-28 10:33

    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();
            }
        }
    

提交回复
热议问题