当我使用itextsharp将Html转换为Pdf时,它是错误的:找到无效的嵌套标签,预期关闭标签Img [英] When I use itextsharp to Convert Html To Pdf ,It's Wrong :Invalid Nested Tag Strong Found, Expected Closing Tag Img

查看:548
本文介绍了当我使用itextsharp将Html转换为Pdf时,它是错误的:找到无效的嵌套标签,预期关闭标签Img的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

找到无效的嵌套标签,预期结束标签img

Invalid nested tag strong found, expected closing tag img

推荐答案

因为预期的结束标签img,当我完成丢失的标签时,它的工作正常.. .. (错误)====> (确定)
because of the expected closing tag img , When I completing the missing tag ,It's work ok....(wrong)====>(Ok)


这是一个示例iTextSharp pdf创建程序。

你必须从SourceForge或其他网站下载iTextSharp。

Here is a sample iTextSharp pdf create program.
You must download iTextSharp from SourceForge or other site.
using iTextSharp.text;
using iTextSharp.text.html.simpleparser;
using iTextSharp.text.pdf;
using System.Web.UI.HtmlControls;
...
protected void Button1_Click(Object sender,System.EventArgs e)
        {
            Response.ContentType = "application/pdf";
            Response.AddHeader("content-disposition", "attachment;filename=this.pdf");
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            StringWriter sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);
            HtmlForm frm = new HtmlForm();
            GridView1.AllowPaging = false;
            GridView1.Parent.Controls.Add(frm);
            frm.Controls.Add(GridView1);
            frm.RenderControl(hw);
            StringReader sr = new StringReader(sw.ToString());
            Document PDFdoc = new Document(PageSize.A4, 10.0F, 10.0F, 10.0F, 0.0F);
            iTextSharp.text.html.simpleparser.HTMLWorker htmlparser =   new iTextSharp.text.html.simpleparser.HTMLWorker(PDFdoc);
            PdfWriter.GetInstance(PDFdoc, Response.OutputStream);
            PDFdoc.Open();
            htmlparser.Parse(sr);
            PDFdoc.Close();
            Response.Write(PDFdoc);
            Response.End();
        }


这篇关于当我使用itextsharp将Html转换为Pdf时,它是错误的:找到无效的嵌套标签,预期关闭标签Img的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆