【问题标题】:Cannot convert HTML (http://www.google.co.in/) to PDF using iTextSharp无法使用 iTextSharp 将 HTML (http://www.google.co.in/) 转换为 PDF
【发布时间】:2012-08-10 15:10:17
【问题描述】:

我正在使用 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;           
}

我已经从here 引用了createPDF 函数。

但我遇到以下错误

无法将“iTextSharp.text.html.simpleparser.CellWrapper”类型的对象转换为“iTextSharp.text.Paragraph”类型。

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

【问题讨论】:

    标签: c#-4.0 itextsharp


    【解决方案1】:

    没有人听! HTMLWorker

    • 已过时。
    • 不会被维护。
    • 它已被 XML-Worker 取代。

    【讨论】:

    猜你喜欢
    • 2015-05-09
    • 1970-01-01
    • 2022-03-07
    • 1970-01-01
    • 2014-09-29
    • 1970-01-01
    • 2011-05-22
    相关资源
    最近更新 更多