【问题标题】:Closing tag img error in itext xmlworker. Expected closing tag img error in itext xmlworkeritext xmlworker 中的关闭标记 img 错误。 itext xmlworker中的预期结束标记img错误
【发布时间】:2017-11-21 18:38:54
【问题描述】:

我真的需要你的帮助!我知道这个问题被问了几次,但我没有看到任何答案......所以,当我尝试转换包含 img 标签的 div 标签时,我得到一个异常 -

找到无效的嵌套标签 div,应为结束标签 img

我的html是

 <div id = "Grid">
      <img src="img/q12.gif" />
 </div>

我的 vb.net 代码是

    Dim sr As New StringReader(Request.Form(hfGridHtml.UniqueID))
    Dim pdfDoc As New Document(PageSize.A4, 10.0F, 10.0F, 10.0F, 10.0F)
    Dim writer As PdfWriter = PdfWriter.GetInstance(pdfDoc, New 
      FileStream(Context.Server.MapPath("~/out.pdf"), FileMode.CreateNew))
    pdfDoc.Open()
    XMLWorkerHelper.GetInstance().ParseXHtml(writer, pdfDoc, sr)
    pdfDoc.Close()
    Response.Redirect("http://localhost:61834/ejik.pdf")
    Response.ContentType = "application/pdf"
    Response.Cache.SetCacheability(HttpCacheability.NoCache)
    Response.Write(pdfDoc)
    Response.End()

而我的 JS 是

 $(function () {
    $("[id*=btnExport]").click(function () {
        $("[id*=hfGridHtml]").val($("#Grid").html());
    });
});

感谢您的回答

【问题讨论】:

  • 整个源 HTML 肯定是格式良好的 XHTML 吗?
  • 是的,只是仔细检查了
  • 异常是否有堆栈跟踪?如果是,是否指定了抛出异常的行号?
  • 第 27 行:Dim writer As PdfWriter = PdfWriter.GetInstance(pdfDoc, New FileStream(Context.Server.MapPath("~/out.pdf"), FileMode.CreateNew)) 第 28 行:pdfDoc。 Open() 第 29 行:XMLWorkerHelper.GetInstance().ParseXHtml(writer, pdfDoc, sr) 第 30 行:pdfDoc.Close() 第 31 行:Response.Redirect("localhost:61834/out.pdf")
  • 其中哪些会引发 Invalid-nested-tag 异常?第 29 行?

标签: javascript html asp.net vb.net itext


【解决方案1】:

也许有人会面临同样的问题。我发现是什么原因。当我做 $("[id*=hfGridHtml]").val($("#Grid").html());它返回 img 标签而不关闭“/”。我确信有一些适当的解决方案,但我只需添加结束标记“/”就可以了!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-06-16
    • 1970-01-01
    • 1970-01-01
    • 2012-08-19
    • 2016-10-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多