我正在使用下面的代码将sharepoint aspx页面内容转换为pdf但在解析htmlstring时抛出此错误:“找到无效的嵌套标记div,预期结束标记脚本”如何处理这种无效标记或标记关闭通过C#代码发布,以便我可以将有效的htmlString传递给方法。
//Create a byte array that will eventually hold our final PDF
Byte[] bytes;
//Boilerplate iTextSharp setup here
//Create a stream that we can write to, in this case a MemoryStream
using (var ms = new MemoryStream()) {
//Create an iTextSharp Document which is an abstraction of a PDF but **NOT** a PDF
using (var doc = new Document()) {
//Create a writer that's bound to our PDF abstraction and our stream
using (var writer = PdfWriter.GetInstance(doc, ms)) {
//Open the document for writing
doc.Open();
//Our sample HTML
var example_html = GetHtmlSource(HttpContext.Current.Request.Url.ToString());
using (var srHtml = new StringReader(example_html)) {
//Parse the HTML
iTextSharp.tool.xml.XMLWorkerHelper.GetInstance().ParseXHtml(writer, doc, srHtml); **In this line throwing exception**
}
}
doc.Close();
}
}
bytes = ms.ToArray();