在 .NET 应用程序中使用 ApacheFOP v1.0

发布于 2024-09-28 07:59:43 字数 533 浏览 0 评论 0原文

有人成功地将 Apache FOP v1.0 库编译为 .NET DLL 吗?我正在使用 http://onjava.com 中找到的 IKVM 语法/pub/a/onjava/2004/08/18/ikvm.html;然而,编译后的DLL似乎不完整。例如,我无法将 FopFactory 对象实例化为:

using org.apache.fop.apps;

namespace Utils
{
     public class PdfRender
     {
          public void Render()
          {
            FOUserAgent foUserAgent = fop.getUserAgent();
            FopFactory fopFactory = FopFactory.newInstance();
          }
     }
}

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

素染倾城色 2024-10-05 07:59:43

(由 FOP 用户组的人员提供)

先决条件:已安装 IKVM 0.44.0.5。

  1. http://xmlgraphics.apache.org/fop/1.0/ 下载 FOP 1.0 index.html#download
  2. 将所有 JAR 文件复制到 C:\Fop\Build\
  3. 打开命令提示符并运行以下命令:ikvmc -target:library -reference:IKVM。 OpenJDK.Core.dll -recurse:C:\Fop\Build\\*.jar -version:1.0 -out:C:\Fop\fop.dll
  4. 在 Visual Studio 项目中,添加对 的引用fop.dllIKVM.OpenJDK.*.dllIKVM.Runtime.dll

(Courtesy of the folks on the FOP Users Group)

Prerequisite: IKVM 0.44.0.5 installed.

  1. Download FOP 1.0 from http://xmlgraphics.apache.org/fop/1.0/index.html#download
  2. Copy all JAR files to C:\Fop\Build\
  3. Open a command prompt and run the following: ikvmc -target:library -reference:IKVM.OpenJDK.Core.dll -recurse:C:\Fop\Build\\*.jar -version:1.0 -out:C:\Fop\fop.dll
  4. In your Visual Studio project, add references to fop.dll, IKVM.OpenJDK.*.dll and IKVM.Runtime.dll
野侃 2024-10-05 07:59:43

我尝试了 ClayB 建议的方法,但没有成功。

我使用了 IKVM 0.44 和 0.46 与 FOP 0.95 和 1.0 的组合。但没有任何作用!有一些 java 库丢失并导致错误。还发生了 .net 异常:无法在 System.Security 命名空间中加载类型。我什至尝试按照 Avik Sengupta 在 http://onjava.com/pub/a/onjava/2004/08/18/ikvm.html,但卡在 lib\batik-all-1.7.jar 上。除非有人有任何进一步的解决方法,否则我确信这种方法不再适用于最新的套件。

然而,我发现了一种不同的方法,允许从 .net 调用 FOP。我希望这会对某人有所帮助:

try {
    ProcessStartInfo p = new ProcessStartInfo(fopPath + "fop.bat");
    p.Arguments = String.Format("{0} {1}", foFilePath, pdfFilePath);
    p.WindowStyle = ProcessWindowStyle.Hidden;
    p.WorkingDirectory = fopPath;
    Process proc = new System.Diagnostics.Process();
    proc.StartInfo = p;

    proc.Start();
    proc.WaitForExit();
    }
catch() {
}

请阅读原始文章:http://www.ptperalta.net/index.php/technology/using-apache-fop-in-net.html

I tried the approach suggested by ClayB without any success.

I used the combinations of IKVM 0.44 and 0.46 with FOP 0.95 and 1.0. But nothing worked! There're some java libs are missing and causing errors. There's also an .net exception occured: could not load type in System.Security namespace. I even tried to compile each .jar file to a dll as suggested by Avik Sengupta at http://onjava.com/pub/a/onjava/2004/08/18/ikvm.html, but got stuck on lib\batik-all-1.7.jar. Unless anyone have got any further workrounds, I'm convinced this approach is no longer working with the latest kits.

However, I found a different approach which allows one to call FOP from .net. I hope this will help someone:

try {
    ProcessStartInfo p = new ProcessStartInfo(fopPath + "fop.bat");
    p.Arguments = String.Format("{0} {1}", foFilePath, pdfFilePath);
    p.WindowStyle = ProcessWindowStyle.Hidden;
    p.WorkingDirectory = fopPath;
    Process proc = new System.Diagnostics.Process();
    proc.StartInfo = p;

    proc.Start();
    proc.WaitForExit();
    }
catch() {
}

Please read the original article at: http://www.ptperalta.net/index.php/technology/using-apache-fop-in-net.html

雨巷深深 2024-10-05 07:59:43

我知道这是一个旧线程,但仍然需要一些研究才能使其正常工作。现在,它可以在 Visual Studio 2013 中通过 NuGet 获得。NuGet 包称为 Crispin.fop。在下面的代码中,我传入一个“fop”文件和我想要创建的新 PDF 文件,然后“瞧”,它就创建好了。

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

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();
        }
    }
好多鱼好多余 2024-10-05 07:59:43

我知道这是一篇旧文章,但这篇文章没有针对 .Net Core 的解决方案。我创建了一个在 .Net Core 中运行的 Apache FOP 版本 2.8 的开源纯端口。看看:

FOP.NetCore
https://github.com/sorcerdon/FOP.NetCore

这是核心:

NuGet version (FOP.NetCore)

由于这是一个纯移植,这意味着它可以执行 Apache FOP 可以执行的任何操作。

I know this is an old post, but this post does not have a solution for .Net Core. I have created an open-source pure port of Apache FOP version 2.8 that runs in .Net Core. Check it out:

FOP.NetCore
https://github.com/sorcerdon/FOP.NetCore

Here is the nuget:

NuGet version (FOP.NetCore)

Since this is a pure port, that means that it can do anything that Apache FOP can do.

兰花执着 2024-10-05 07:59:43

ClayB 为我工作过。请记住第 2 点“将所有 JAR 文件复制到 C:\Fop\Build\”。
“全部”非常重要。请参阅此处我需要的 jar 列表:
- fop.jar
- avalon-framework-4.2.0.jar
- 蜡染-all-1.7.jar
- commons-io-1.3.1.jar
- commons-logging-1.0.4.jar
- 序列化器-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
除 fop 之外的所有 jar 都可以在文件夹“lib”中找到。

ClayB's worked for me. Please keep in mind point 2 "Copy all JAR files to C:\Fop\Build\".
"all" is very important. See here the list of jar's I needed:
- fop.jar
- avalon-framework-4.2.0.jar
- batik-all-1.7.jar
- commons-io-1.3.1.jar
- commons-logging-1.0.4.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
All the jar's other than fop you will find in folder "lib".

冷心人i 2024-10-05 07:59:43

ClatB 也在这里工作过。请记住将所有 IKVM 库添加到您的项目中(使用 Fop 1.1 和 IKVM 7.2.4630.5)。

ClatB`s worked here too. Just remmeber to add ALL IKVM libs to your project (Worked with Fop 1.1 and IKVM 7.2.4630.5).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文