首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iTextSharp xmlworkerhelper的ASP.NET编译器错误

iTextSharp xmlworkerhelper的ASP.NET编译器错误
EN

Stack Overflow用户
提问于 2014-07-25 21:20:49
回答 1查看 14.6K关注 0票数 0

我正在尝试编写一个应用程序,该应用程序将生成一系列我用ASP.NET构建的web报告。因此,我有一个web应用程序来存放这些页面,但我并不是真的想用这个网站来查看这些页面,我想创建我可以交付给我的客户的PDF。

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

代码语言:javascript
复制
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声明上的Using指令或引用。需要哪些参考资料??

代码语言:javascript
复制
            XmlWorkerHelper.GetInstance(doc, new FileStream("test.pdf", FileMode.Create));
            XmlWorker obj = new XmlWorker(doc);

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

代码语言:javascript
复制
            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 ");
        }

    }
}

我的问题:

要解决XmlWorkerHelper和XmlWorker declarations?

  • Is上的编译错误,我需要使用什么reference或XmlWorker指令?

  • 我的报表主要由图形元素组成。在没有很多manipulations?

的情况下,iTextSharp能够生成PDF吗

谢谢..。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-07-25 21:56:10

  1. XMLWorker包含在一个单独的库中,你需要引用这个库,你可以使用pick up the latest here.
  2. Casing,因为XMLWorker很重要,XMLWorker的前四个字母需要大写。一旦你这样做了(并添加了上面的引用),你应该能够右击并让VS自动为你找出using指令。如果不是,你要找的是using iTextSharp.tool.xml;
  3. You'll,你可以试一试看看。如果你的目标是制作一个PDF,看起来和现有的网页一模一样,或者你有相当复杂的HTML和CSS,你最好试试wkhtmltopdf。iTextSharp的XMLWorker之所以闪亮,是因为它能将超文本标记语言和CSS解析成iTextSharp对象,你可以在写入之前随意操作这些对象。并不是所有的HTML/CSS范例/规则都可以很容易地用这种方式表达,XMLWorker也不支持这些。wkhtmltopdf可以制作非常漂亮的PDF文件,但是在转换过程中你不能做任何调整。
票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24956740

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档