When this string
<DIV align=center> <SPAN>abc <SPAN > </SPAN>def </SPAN> </DIV>
is used to create an HtmlFragment it breaks the PDF generation process.
If the spaces after abc and def are removed, generation of the document works.
Here is the code that breaks, followed by the same code with a ‘while’ loop that lets generation happen:
protected static HtmlFragment GetHtmlFragment(string text)
{
if (text == null)
{
text = “”;
}
text = text.Replace("\r", “”);
text = text.Replace("\n", " “);
text = text.Replace(”¿", “”);
//remove XML tags if any
text = Regex.Replace(text, "(?s)<!--.*?-->", " ");
text = Regex.Replace(text, @"url\((['""].*?[""'])\)", "");
text = Regex.Replace(text, @"url['""].*?[""']", "");
text = Regex.Replace(text, @"url\((.*?)\)", "");
text = Regex.Replace(text, @"face=['""].*?[""']", "");
text = Regex.Replace(text, @"</select.*?>", "");
text = Regex.Replace(text, @"<select.*?>", "");
text = Regex.Replace(text, @"</img.*?>", "");
text = Regex.Replace(text, @"<img.*?>", "");
text = Regex.Replace(text, @"</font.*?>", "");
text = Regex.Replace(text, @"<font.*?>", "");
text = Regex.Replace(text, @"</b.*?>", "");
text = Regex.Replace(text, @"<b.*?>", "");
var fragment = new HtmlFragment(text);
fragment.TextState = new TextState();
return fragment;
}
if the above string is processed, later on during the generation of the document we get a crash.
Here is the same code with a loop that arbitrarily removes spaces if the string contains '<SPAN>'
:
protected static HtmlFragment GetHtmlFragment(string text)
{
if (text == null)
{
text = "";
}
text = text.Replace("\r", "");
text = text.Replace("\n", " ");
text = text.Replace("¿", "");
//remove XML tags if any
text = Regex.Replace(text, "(?s)<!--.*?-->", " ");
text = Regex.Replace(text, @"url\((['""].*?[""'])\)", "");
text = Regex.Replace(text, @"url['""].*?[""']", "");
text = Regex.Replace(text, @"url\((.*?)\)", "");
text = Regex.Replace(text, @"face=['""].*?[""']", "");
text = Regex.Replace(text, @"</select.*?>", "");
text = Regex.Replace(text, @"<select.*?>", "");
text = Regex.Replace(text, @"</img.*?>", "");
text = Regex.Replace(text, @"<img.*?>", "");
text = Regex.Replace(text, @"</font.*?>", "");
text = Regex.Replace(text, @"<font.*?>", "");
text = Regex.Replace(text, @"</b.*?>", "");
text = Regex.Replace(text, @"<b.*?>", "");
//arbitrarily remove spaces in this use case to prove malfunction
if(text.Contains("SPAN"))
{
while(text.Contains(" "))
{
text = text.Replace(" ", string.Empty);
}
}
var fragment = new HtmlFragment(text);
fragment.TextState = new TextState();
return fragment;
}
If you need a console project created that proves this malfunction I could create one. Let me know if this code can be duplicated on your end and then the string above duplicates the malfunction. I think it will.
If not, let me know.