2
I have an Asp.Net MVC project where I would like to convert an HTML string to RTF in Controller.
I’ve 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 soon in the first line presented, I got the following error:
{"Unable to create an instance of Activex control '8856f961-340a-11d0-a96b-00c04fd705a2' because the current thread is not in a STA (single-threaded Apartment)."}
So I continued the research and got this project.
I downloaded Solution, compiled the Class Library project, copied the DLL (Markupconverter.dll) for my project, where I made the proper reference, and tried its use in the following way:
IMarkupConverter markupConverter;
markupConverter = new MarkupConverter.MarkupConverter();
var rtfResult = markupConverter.ConvertHtmlToRtf(meuHtml);
But I got the following mistake:
{"The call thread must be STA, because many components of the User Interface so require."}
I did several researches, but found nothing practical and free of charge to perform HTML to RTF conversion.
Thank you very much, Bastei change some things in the code, because this you used refers to converting RTF to HTML, and I need the opposite... But 100% working here! I hadn’t quite understood the documentation.
– Jedaias Rodrigues
I leave just one observation, that library for some reason can not convert
ó
andÓ
for your RTF correspondents, but I was able to make it work by doing a Replace before conversion.html.Replace("ó", "ó");
– Jedaias Rodrigues