无法使用 iTextSharp 将 HTML (http://www.google.co.in/) 转换为 PDF



我正在使用iTextSharp将HTML(源站点是google: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;           
}

我已经从这里引用了createPDF函数。

但是我遇到了以下错误

无法将类型为"iTextSharp.text.html.simpleparser.CellWrapper"的对象转换为键入"iTextSharp.text.Paragraph"。

iTextSharp库有问题吗?顺便说一下,我正在使用itextsharp-dll-core-5.3.0

没人听!HTMLWorker

  • 已过时。
  • 不会维护。
  • 它被替换为XML-Worker。

最新更新