【发布时间】:2014-09-17 08:49:42
【问题描述】:
我正在尝试编写一个应用程序来触发一系列我在 ASP.NET 中构建的网络报告。所以我有一个页面所在的 Web 应用程序,但我真的不想使用该网站查看页面,我想创建可以交付给我的客户的 PDF。
我正在尝试编写的应用程序是一个控制台应用程序,用 c# 在 Visual Studio 2010 中编写,并使用 iTextSharp v5.5.2 和 .NET 4.5。它目前只是一个框架,因为我还没有进入“触发 PDF”部分。我正在从网络访问一个页面并尝试将其保存为 PDF,但我找不到任何关于我遇到的编译错误的信息。我在应用程序中有以下 Using 指令:
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();
// 以下几行表明我需要一个 Using 指令或一个引用 // 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?
谢谢...
【问题讨论】:
标签: c# asp.net pdf itextsharp xmlworker