2011-10-28 45 views
0
Document document = new Document(); 
string str = Pagehtml; 

//writer - have our own path!!! 
PdfWriter.GetInstance(document, new FileStream(Server.MapPath(".") + "parsetest.pdf", FileMode.Create)); 
document.Open(); 
//here when it parse the html gives exception unknown color format should be #RGB 
ArrayList htmlarraylist = iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(new StringReader(str), null); 

//add the collection to the document 
for (int k = 0; k < htmlarraylist.Count; k++) 
{ 
    document.Add((IElement)htmlarraylist[k]); 
} 

这是我的代码中,我解析HTML代码,但是当它解析HTML它给未知色彩格式的例外未知色彩格式异常从HTML到PDF使用iTextSharp的

回答

0

你会需要发布HTML以供我们查看导致错误的确切原因。但最终的错误信息应该非常明显。就iTextSharp而言,HTML的某些部分有一些无效的RGB值。 Per spec(链接到5,但与之前版本相同)HTML中的所有颜色都应采用#RRGGBB格式。然而,iText似乎也允许#RGB,但我期望它是用于CSS解析。最后,如果你使用CSS,你可以使用rgb(R,G,B)

Line 260 of the most recent version (5.1.1.2) shows you the line throwing the actual exception.

+0

感谢您的回复,我得到了我的问题的解决方案,这是由于内联CSS我在页面中使用我有定义非RGB格式的颜色现在这个问题是由RGB定义它们解决格式。 –