将xml文件转换为pdf c#

问题描述 投票:0回答:3

我想将xml文件转换为c#中的pdf文件。

这是我的代码。

private void printAllDataReceiveToolStripMenuItem_Click(object sender, EventArgs e)
    {            
        // Load the FO style sheet.
        XslCompiledTransform xslt = new XslCompiledTransform();
        xslt.Load("bookFo.xsl");

        // Execute the transform and output the results to a file.
        xslt.Transform("books.xml", "books.fo");
    }
    private void GeneratePDF(string foFile, string pdfFile)
    {
        FileInputStream streamFO = new FileInputStream(foFile);
        InputSource src = new InputSource(streamFO);
        FileOutputStream streamOut = new FileOutputStream(pdfFile);
        Driver driver = new Driver(src, streamOut);
        driver.setRenderer(1);
        driver.run();
        streamOut.close();
    }

但是,FileInputStream,InputSource和FileOutputStream显示错误

找不到类型或命名空间名称'FileInputStream',InputSource,FIleOutputStream(您是否缺少using指令或程序集引用?)

这就是我导入的东西(我不知道它的正确用语)

    using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Timers;
using System.Net.Sockets;
using System.Threading;
using System.Net;

//add data to xml
using System.Xml;
using System.Xml.Linq;
//convert to pdf
using System.Xml.Xsl;
using System.Xml.XPath;


using System.IO;

我一直在搜索互联网,它说我应该添加这个。

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

即使我正在使用它,它说使用指令或程序集引用时缺少相同的错误。谁能帮我这个?

c# xml pdf
3个回答
0
投票

你可能还需要dll;我发现这篇文章的答案标记为正确。它解释了如何生成dll:Using ApacheFOP v1.0 in .NET application


0
投票

FileInputStream是一个java类。 java.io是一个java命名空间。你不能在.NET中明智地使用它们。你似乎是混合平台,这就是你遇到问题的原因。

.NET中FileInputStream的近似值可能是StreamReader;对于FileOutputStream使用StreamWriter。我不确定InputSource在做什么,所以我不能在那里提供解决方案。

如果您需要更多帮助,您应该包括您正在使用哪些第三方库的详细信息(因为Driver不是标准类)以及您引用的网站,因为在.NET应用程序中添加java.io是在大多数情况下不太可能工作......


0
投票

vjslib.dll不适用于.NET Framework 4.0。以下是详细信息:msdn details

如果您希望应用程序正常工作,请将目标框架更改为.Net Framework 3.0或2.0

© www.soinside.com 2019 - 2024. All rights reserved.