Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# iTextSharp xmlworkerhelper的ASP.NET编译器错误_C#_Asp.net_Pdf_Itextsharp_Xmlworker - Fatal编程技术网

C# iTextSharp xmlworkerhelper的ASP.NET编译器错误

C# iTextSharp xmlworkerhelper的ASP.NET编译器错误,c#,asp.net,pdf,itextsharp,xmlworker,C#,Asp.net,Pdf,Itextsharp,Xmlworker,我正在尝试编写一个应用程序,它将触发我在ASP.NET中构建的一系列web报告。因此,我有一个网页所在的web应用程序,但我真的不想使用该网站查看网页,我想创建可以交付给客户的PDF 我尝试编写的应用程序是一个控制台应用程序,在Visual Studio 2010中用c#编写,使用iTextSharp v5.5.2和.NET 4.5。它目前只是一个框架,因为我还没有谈到“启动PDF”部分。我正在从网络上访问一个页面,并试图将其保存为PDF格式,但我找不到任何有关编译错误的信息。我在应用程序中有以

我正在尝试编写一个应用程序,它将触发我在ASP.NET中构建的一系列web报告。因此,我有一个网页所在的web应用程序,但我真的不想使用该网站查看网页,我想创建可以交付给客户的PDF

我尝试编写的应用程序是一个控制台应用程序,在Visual Studio 2010中用c#编写,使用iTextSharp v5.5.2和.NET 4.5。它目前只是一个框架,因为我还没有谈到“启动PDF”部分。我正在从网络上访问一个页面,并试图将其保存为PDF格式,但我找不到任何有关编译错误的信息。我在应用程序中有以下使用指令:

using iTextSharp;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html;
using iTextSharp.text.xml;
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using iTextSharp.text.io;
using iTextSharp.text.xml.simpleparser;
using iTextSharp.text.html.simpleparser;

namespace ConsoleApplication1
{
    public partial class BuildReports : System.Web.UI.Page
    {
        static void Main(string[] args)
        {
            WebRequest wReq = WebRequest.Create("http://www.somesite.com/");
            WebResponse wRsp = null;

            try
            {
                wRsp = wReq.GetResponse();
            }
            catch (Exception e)
            {
                Console.WriteLine("{0} exception caught.", e);
            }

            Console.WriteLine(((HttpWebResponse)wRsp).StatusDescription);
            Stream sRsp = wRsp.GetResponseStream();
            StreamReader sRdr = new StreamReader(sRsp);
            string sHtml = string.Empty;
            sHtml = sRdr.ReadToEnd();
            Console.WriteLine(sHtml);
            StringReader sr = new StringReader(sHtml);
            Document doc = new Document();
//以下几行表示我需要在 //XmlWorkerHelper和XmlWorker声明。需要哪些参考资料

            XmlWorkerHelper.GetInstance(doc, new FileStream("test.pdf", FileMode.Create));
            XmlWorker obj = new XmlWorker(doc);
//---------------------------------------------------------------------------------------

            doc.Open();
            obj..Parse(sr);
            doc.Close();
            sRdr.Close();
            sRsp.Close();
        }
    }
    public class CustomHTTPModule : IHttpModule
    {
        public CustomHTTPModule()
        {
            // Class constructor.
        }

        // Classes that inherit IHttpModule  
        // must implement the Init and Dispose methods. 
        public void Init(HttpApplication app)
        {

            app.AcquireRequestState += new EventHandler(app_AcquireRequestState);
            app.PostAcquireRequestState += new EventHandler(app_PostAcquireRequestState);
        }

        public void Dispose()
        {
            // Add code to clean up the 
            // instance variables of a module.
        }

        // Define a custom AcquireRequestState event handler. 
        public void app_AcquireRequestState(object o, EventArgs ea)
        {
            HttpApplication httpApp = (HttpApplication)o;
            HttpContext ctx = HttpContext.Current;
            ctx.Response.Write(" Executing AcquireRequestState ");
        }

        // Define a custom PostAcquireRequestState event handler. 
        public void app_PostAcquireRequestState(object o, EventArgs ea)
        {
            HttpApplication httpApp = (HttpApplication)o;
            HttpContext ctx = HttpContext.Current;
            ctx.Response.Write(" Executing PostAcquireRequestState ");
        }

    }
}
我的问题:
1.解决XmlWorkerHelper和XmlWorker声明上的编译错误需要什么引用或使用指令?
2.是否有其他我遗漏的东西导致编译错误?
3.我的报告主要由图形元素组成。iTextSharp是否能够在无需大量操作的情况下生产PDF

谢谢

  • XMLWorker
    包含在一个单独的库中,您可以参考该库

  • 大小写很重要,
    XMLWorker
    的前四个字母需要大写。一旦您这样做(并添加上面的参考),您应该能够右键单击,让VS使用指令为您自动计算出
    。如果没有,您将使用iTextSharp.tool.xml查找
  • 你只要试试看就行了。如果你的目标是制作一个看起来与现有网页一模一样的PDF,或者你有相当复杂的HTML和CSS,那么你最好尝试一下。iTextSharp的XMLWorker非常出色,因为它将HTML和CSS解析为iTextSharp对象,您可以在写入PDF之前选择对这些对象进行操作。并非所有的HTML/CSS范例/规则都可以用这种方式轻松表达,XMLWorker不支持这些。wkhtmltopdf可以制作非常好看的PDF,但在转换过程中,您无法真正调整任何内容
  • XMLWorker
    包含在一个单独的库中,您可以参考该库

  • 大小写很重要,
    XMLWorker
    的前四个字母需要大写。一旦您这样做(并添加上面的参考),您应该能够右键单击,让VS使用
    指令为您自动计算出
    。如果没有,您将使用iTextSharp.tool.xml查找
  • 你只要试试看就行了。如果你的目标是制作一个看起来与现有网页一模一样的PDF,或者你有相当复杂的HTML和CSS,那么你最好尝试一下。iTextSharp的XMLWorker非常出色,因为它将HTML和CSS解析为iTextSharp对象,您可以在写入PDF之前选择对这些对象进行操作。并非所有的HTML/CSS范例/规则都可以用这种方式轻松表达,XMLWorker不支持这些。wkhtmltopdf可以制作非常好看的PDF,但在转换过程中,您无法真正调整任何内容

  • 向引用中添加了iTextSharp.XMLWorker。这解决了XMLWorker问题。。。非常感谢。为什么这个额外的DLL没有包含在发行版下载中?
    使用iTextSharp.tool.xml变魔术了!谢谢你,克里斯Haas@AbhishekGhosh但it gets error tool不包含在iTextSharp中。已将iTextSharp.XMLWorker添加到引用中。这解决了XMLWorker问题。。。非常感谢。为什么这个额外的DLL没有包含在发行版下载中?
    使用iTextSharp.tool.xml变魔术了!谢谢你,克里斯Haas@AbhishekGhosh但iTextSharp中不包含该错误工具。