我有以下 HTML。看input tag
下面comment
(问题的真正原因)。
<div class="col-xs-12 GPAMainForm">
<div class="col-xs-10 col-xs-offset-1">
<div style="border: 1px double black; padding: 2px">
<div>
<table class="table">
<tr class="border">
<td class="border">
<label class="control-label">Company Name</label>
</td>
<td class="border">
<input type="text" />
<!--
If I remove input tag, pdf gets generated else it show error like:
`Invalid nested tag td found, expected closing tag input`
-->
</td>
</tr>
</table>
</div>
</div>
</div>
</div>
而不是input tag
我试图去<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
错误
找到无效的嵌套标记 td,预期结束标记输入
问题原因
但是当我看到解析的 html 时,我可以清楚地知道它以某种方式删除/
并生成<input type="text>
.
与<asp:textbox>
它相同删除结束标签并生成
<input name="ctl00$MainContent$TextBox2" id="MainContent_TextBox2" type="text">
请帮忙。
编辑帖子:
try
{
string htmlContent = TextBox1.Text.Replace("\r", "\n").Replace("\n", "");// you html code (for example table from your page)
Document doc = new Document();
string FileName = Guid.NewGuid().ToString();
PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream("C:\\Nikhil Shah\\Projects\\Local Projects\\PracticeDemo\\PracticeDemo\\PDF\\" + FileName + ".pdf", FileMode.Create));
doc.Open();
var cssResolver = new StyleAttrCSSResolver();
var cssFile = XMLWorkerHelper.GetCSS(new FileStream(HttpContext.Current.Server.MapPath(@"~\Content\myCss.css"), FileMode.Open));
cssResolver.AddCss(cssFile);
CssAppliers ca = new CssAppliersImpl();
HtmlPipelineContext hpc = new HtmlPipelineContext(ca);
hpc.SetTagFactory(Tags.GetHtmlTagProcessorFactory());
// PIPELINES
PdfWriterPipeline pdf = new PdfWriterPipeline(doc, writer);
HtmlPipeline htmlPipe = new HtmlPipeline(hpc, pdf);
CssResolverPipeline css = new CssResolverPipeline(cssResolver, htmlPipe);
XMLWorker worker = new XMLWorker(css, true);
XMLParser p = new XMLParser(worker);
StringReader sr = new StringReader(htmlContent);
p.Parse(sr);
doc.Close();
Response.ContentType = "application/pdf";
Response.AppendHeader("Content-Disposition", "attachment; filename=" + FileName + ".pdf");
Response.TransmitFile(Server.MapPath(@"~\PDF\" + FileName + ".pdf"));
Response.End();
}
catch (Exception ex)
{
Response.Write(ex.Message.ToString());
}