1
我正在使用iTextSharp将HTML(源网站为google:http://www.google.co.in/)转换为PDF。无法使用iTextSharp将HTML(http://www.google.co.in/)转换为PDF
我的代码:
protected void Page_Load(object sender, EventArgs e)
{
WebClient wc = new WebClient();
string HTMLCode = wc.DownloadString("http://www.google.co.in/");
var result = createPDF(HTMLCode);
}
private MemoryStream createPDF(string html)
{
MemoryStream msOutput = new MemoryStream();
TextReader reader = new StringReader(html);
// step 1: creation of a document-object
Document document = new Document(PageSize.A4, 30, 30, 30, 30);
// step 2:
// we create a writer that listens to the document
// and directs a XML-stream to a file
PdfWriter writer = PdfWriter.GetInstance(document, msOutput);
// step 3: we create a worker parse the document
HTMLWorker worker = new HTMLWorker(document);
// step 4: we open document and start the worker on the document
document.Open();
worker.StartDocument();
// step 5: parse the html into the document
worker.Parse(reader);
// step 6: close the document and the worker
worker.EndDocument();
worker.Close();
document.Close();
return msOutput;
}
我从here提到的createPDF功能。
但我遇到下面的错误
无法投类型的对象iTextSharp.text.html.simpleparser.CellWrapper为键入“iTextSharp.text.Paragraph”。
iTextSharp库有些问题吗?顺便说一下,我使用itextsharp-dll-core-5.3.0
它在哪个命名空间中..我找不到XMLWorkerHelper或XMLWorker ...请纠正我,如果我错了 – 2012-08-14 12:25:20
XML-Worker现在是一个附加项目。你可以在这里找到它:http://sourceforge.net/projects/itextsharp/files/xmlworker/和它的样本位于这里:https://itextsharp.svn.sourceforge.net/svnroot/itextsharp/trunk/src/演员/ itextsharp.xmlworker.testApps / – VahidN 2012-08-14 18:41:34