I have a project in Asp.Net MVC where I would like to convert an HTML string to RTF on the Controller.
I have tried the following ways:
using(var webBrowser = new WebBrowser()){
webBrowser.CreateControl();
webBrowser.DocumentText = minhaStringHTML;
while(webBrowser.DocumentText != minhaStringHTML)
{
Application.DoEvents();
}
webBrowser.Document.ExecCommand("SelectAll", false, null);
webBrowser.Document.ExecCommand("Copy", false, null);
using(var rtc = new RichTextBox())
{
meuRTF = rtc.Paste();
}
}
But on the first line , I get the following error:
{"Can not create an instance of the ActiveX control '8856f961-340a-11d0-a96b-00c04fd705a2' because the current thread is not in a STA (single-threaded apartment). "}
So I continued the searches and got this project .
I downloaded Solution, compiled the Class Library project, copied the DLL (MarkupConverter.dll) for my project, where I made the reference, and tried its use as follows:
IMarkupConverter markupConverter;
markupConverter = new MarkupConverter.MarkupConverter();
var rtfResult = markupConverter.ConvertHtmlToRtf(meuHtml);
But I got the following error:
{"The calling thread must be STA, because many components of the User interface so require. "}
I did a lot of research but found nothing practical and free to perform the conversion from HTML to RTF.