ASP.NET编译器与iTextSharp的xmlworkerhelper错误 [英] ASP.NET Compiler errors with iTextSharp xmlworkerhelper

查看:564
本文介绍了ASP.NET编译器与iTextSharp的xmlworkerhelper错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写,将火过一系列的,我已经建在ASP.NET Web报表的应用程序。所以,我有地方住页面的Web应用程序,但我真的不希望使用的网站上看到的网页,我要创建PDF文件,我可以提供给我的客户。

我试图写的应用程序是一个控制台应用程序,写在C#Visual Studio 2010和使用iTextSharp的v5.5.2和.NET 4.5。它目前只是一个,因为我还没有得到的发射过的PDF文件的部分还没有框架。我从网络访问一个网页,并试图将其保存为PDF格式,但我不能找到编译错误我得到的任何信息。我在应用程序中使用如下指令:

 使用iTextSharp的;
使用iTextSharp.text;
使用iTextSharp.text.pdf;
使用iTextSharp.text.html;
使用iTextSharp.text.xml;
使用系统;
System.Collections中使用;
使用System.Collections.Generic;
使用System.IO;
使用System.Linq的;
使用System.Net;
使用System.Text;
使用的System.Web;
使用System.Web.UI程序;
使用System.Web.UI.WebControls;
使用的System.Xml;
使用iTextSharp.text.io;
使用iTextSharp.text.xml.simpleparser;
使用iTextSharp.text.html.simpleparser;命名空间的ConsoleApplication1
{
    公共部分类BuildReports:System.Web.UI.Page
    {
        静态无效的主要(字串[] args)
        {
            WebRequest的WREQ = WebRequest.Create(http://www.somesite.com/);
            WebResponse类WRSP = NULL;            尝试
            {
                WRSP = wReq.GetResponse();
            }
            赶上(例外五)
            {
                Console.WriteLine({0}异常捕获,E);
            }            Console.WriteLine(((HttpWebResponse)WRSP).StatusDescription);
            流SRSP = wRsp.GetResponseStream();
            StreamReader的sRdr =新的StreamReader(SRSP);
            字符串SHTML =的String.Empty;
            SHTML = sRdr.ReadToEnd();
            Console.WriteLine(SHTML);
            StringReader SR =新StringReader(SHTML);
            文档DOC =新的文档();

//下面的线,表明我需要一个使用指令或在一个参考
// XmlWorkerHelper和XmlWorker声明。参考什么需要?

  XmlWorkerHelper.GetInstance(文件,新的FileStream(的test.pdf,FileMode.Create));
            XmlWorker的obj =新XmlWorker(DOC);

// --------------------------------------------- ------------------------------------------

  doc.Open();
            obj..Parse(SR);
            doc.Close();
            sRdr.Close();
            sRsp.Close();
        }
    }
    公共类CustomHTTPModule:IHttpModule的
    {
        公共CustomHTTPModule()
        {
            //类的构造函数。
        }        //继承IHttpModule的类
        //必须实现的Init和Dispose方法。
        公共无效初始化(HttpApplication的应用程序)
        {            app.AcquireRequestState + =新的EventHandler(app_AcquireRequestState);
            app.PostAcquireRequestState + =新的EventHandler(app_PostAcquireRequestState);
        }        公共无效的Dispose()
        {
            //添加code清理
            //模块的实例变量。
        }        //定义一个定制的AcquireRequestState事件处理程序。
        公共无效app_AcquireRequestState(对象o,EventArgs的EA)
        {
            HttpApplication的httpApp =(HttpApplication的)O;
            HttpContext的CTX = HttpContext.Current;
            ctx.Response.Write(执行的AcquireRequestState);
        }        //定义自定义PostAcquireRequestState事件处理程序。
        公共无效app_PostAcquireRequestState(对象o,EventArgs的EA)
        {
            HttpApplication的httpApp =(HttpApplication的)O;
            HttpContext的CTX = HttpContext.Current;
            ctx.Response.Write(执行PostAcquireRequestState);
        }    }
}

我的问题:结果
1.什么参考或使用指令,我需要解决编制的XmlWorkerHelper和XmlWorker声明错误?结果
2.是否有别的我失踪的东西是造成编译错误?结果
3.我的报告主要由图形元素。 iTextSharp的将是能够产生PDF文件没有很多操作的?

谢谢...


解决方案

  1. XMLWorker 包含在你需要引用一个单独的库,你可以的拿起这里最新的。

  2. 套管是很重要的, XMLWorker 的前四个字母要大写。一旦你这样做(和上面添加引用),你应该能够右键单击,并自动VS弄清楚使用指示你。如果没有,你正在寻找使用iTextSharp.tool.xml;

  3. 您只好尝试一下,看看。如果你的目标是使的PDF看起来酷似一个现有的网络和/或你有相当复杂的HTML和CSS,你可能会更好努力的 wkhtmltopdf 。 iTextSharp的的XMLWorker眼前一亮,因为它解析HTML和CSS到您可以写入PDF之前可选操作iTextSharp的对象。不是所有的HTML / CSS范式/规则可以很容易地恩pressed这种方式和XMLWorker不支持这些。 wkhtmltopdf可以使真正伟大的PDF文件看,但你真的不能调整在转换过程中任何事情。

I'm trying to write an application that will fire off a series of web reports that I've built in ASP.NET. So I have a web application where the pages live, but I don't really want to use the website to see the pages, I want to create PDFs that I can deliver to my clients.

The application I'm trying to write is a console app, written in Visual Studio 2010 in c# and using iTextSharp v5.5.2 and .NET 4.5. It's currently just a framework as I haven't got to the "firing off PDFs" part yet. I'm accessing a page from the web and trying to save it as a PDF, but I can't find any info on the compile errors I'm getting. I have the following Using directives in the application:

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

// The following lines are indicating that I need a Using directive or a Reference on the // XmlWorkerHelper and XmlWorker declarations. What references are needed??

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

    }
}

My questions:
1. What reference or Using directive do I need to resolve the compile errors on the XmlWorkerHelper and XmlWorker declarations?
2. Is there something else I'm missing that's causing the compile errors?
3. My reports are mainly composed of graphical elements. Will iTextSharp be able to produce the PDFs without a lot of manipulations?

Thanks...

解决方案

  1. XMLWorker is contained in a separate library that you need to reference, you can pick up the latest here.
  2. Casing is important, the first four letters of XMLWorker need to be capitalized. Once you do that (and add the reference above) you should be able to right-click and have VS automatically figure out the using directive for you. If not, you're looking for using iTextSharp.tool.xml;
  3. You'll just have to try it and see. If your goal is to make a PDF that looks exactly like an existing web and/or you have fairly complicated HTML and CSS you might be better off trying wkhtmltopdf. iTextSharp's XMLWorker shines because it parses HTML and CSS into iTextSharp objects that you can optionally manipulate before writing to PDF. Not all HTML/CSS paradigms/rules can be easily expressed this way and XMLWorker doesn't support these. wkhtmltopdf can make really great looking PDFs but you can't really tweak anything during the conversion process.

这篇关于ASP.NET编译器与iTextSharp的xmlworkerhelper错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆