我正在尝试编写一个应用程序,该应用程序将生成一系列我用ASP.NET构建的web报告。因此,我有一个web应用程序来存放这些页面,但我并不是真的想用这个网站来查看这些页面,我想创建我可以交付给我的客户的PDF。
我正在尝试编写的应用程序是一个控制台应用程序,它是用Visual Studio2010在c#中编写的,使用iTextSharp v5.5.2和.NET 4.5。它目前只是一个框架,因为我还没有达到“启动PDF”的部分。我正在从web访问一个页面,并试图将其另存为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();//以下行指示我需要// XmlWorkerHelper和XmlWorker声明上的Using指令或引用。需要哪些参考资料??
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 ");
}
}
}我的问题:
要解决XmlWorkerHelper和XmlWorker declarations?
的情况下,iTextSharp能够生成PDF吗
谢谢..。
发布于 2014-07-25 21:56:10
XMLWorker包含在一个单独的库中,你需要引用这个库,你可以使用pick up the latest here.XMLWorker很重要,XMLWorker的前四个字母需要大写。一旦你这样做了(并添加了上面的引用),你应该能够右击并让VS自动为你找出using指令。如果不是,你要找的是using iTextSharp.tool.xml;wkhtmltopdf。iTextSharp的XMLWorker之所以闪亮,是因为它能将超文本标记语言和CSS解析成iTextSharp对象,你可以在写入之前随意操作这些对象。并不是所有的HTML/CSS范例/规则都可以很容易地用这种方式表达,XMLWorker也不支持这些。wkhtmltopdf可以制作非常漂亮的PDF文件,但是在转换过程中你不能做任何调整。https://stackoverflow.com/questions/24956740
复制相似问题