Getting HTML(Readable) Format from RadRichTextBox using MVC - asp.net-mvc

I am building an application on MVC, where we had same application in MVVM silverlight, we had no problem in using PDF's an RadRichTextBox formats, so in MVC we are using same database same as in MVVM, and here I am having some problem as below
in sql server database we have already stored a radrichtextbox formatted data, and using MVC I am trying to get that data and put it back to PDF(which is working fine in MVVM), and I am able to put it on PDF without any problem, but the format which get it on PDF is not in proper order or its not readable, below I am providing example of format what I have on sql server and what format I am expecting it from there
My question
Is there any way we could use that radrichtextbox format to convert it into HTML format so that I can use it on PDF
since I am using MVC is there any dll, so that i can implement to get right format
NOTE
I already searched in stack forum with no help, and I even contacted Telerik people regarding this all they were able to help me out is for silverlight
and This link from telerik rich-editor will help me to get it into right format which I need but finding hard time to implement
So if there any one could able to help me or even guide me in this would be much helpful for me, Thanks
UNFORMATTED DATA WHICH I GET FROM SQL SERVER
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"> <html xmlns=\"http://www.w3.org/1999/xhtml\"><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /><title>Untitled</title><style type=\"text/css\">\r\n.s_D8D99854 { font-family: 'Verdana';font-style: Normal; } \r\n</style></head><body><p ><span class=\"s_D8D99854\"> hello</span></p></body></html>
AND THIS IS THE FORMAT I SHOULD GET FROM ABOVE

I believe that you can easily strip the content by yourself using the server-side String.Replace method by converting all \" instances to "
If the PDF convertor does not understand the meta tags, the HTML, HEAD and BODY tags then strip them too using regular expressions.

Related

issue when converting html string to pdf using evo pdf library

I got a problem when converting html string to pdf, to be simple, I found the Kendo js/css file I referenced in my html string looks like not working at all.
Detail:
I am working on a project that converting my views(ASP MVC 4.5
) to Pdf using Evo Pdf, in my view, I have used Kendo UI controls, so I reference the Kendo css js file like below in my view file
#Scripts.Render("~/Libs/KendoUI/js/kendo.all.min.js")
<script type="text/javascript" src="#Url.Content("~/Libs/KendoUI/js/kendo.all.min.js")"></script>
When I open the view in browser, all controls works fine, but when I render the view into string, and pass it to Evo SavePdfFromHtmlStringToStream function, the pdf is generated but all the Kendo controls are missing on the pdf.
Ps, I know maybe I can use the absolute URL to convert URL to Pdf, but I am using view with model(model are posted to controller), so I don’t really want to do that.
Actually, I found the solution 2 weeks ago from Evo team, I just need set a base url in the parameters, that's all, now works fine! thanks for all!

How to convert the data into html reading from data base

I am developing an application in which I have used the editor so when the user submit the data the data was send to the sql server in HTML format.
<p><strong><em>fghfghfghfghfghfghfgdfxvbc</em></strong></p> <ol> <li>.
it will not converted in to html tags.
I'm using Asp.net Mvc.
The code is as follow:
When adding raw HTML to a page in ASP.NET MVC, you need to use
#Html.Raw("your html string here")

asp.net mvc rasor #raw does not accept <br>

I have a solution that uses asp.net web api to convert data to pdf.
I am using #Raw to display the data in a html formatted manner. But the problem is that if the json string contains the html <br> it throws an error. Once I change it manually to XHTML <br/> it works fine.
Why can't #Raw handle html breaks ? Is there a better way to handle html tags?
Description
#Raw(#Model.Description)
For security reasons, Raw method is not recommended for using - it does not encode input string. The better solution, especially when you already use Web API, would be to just return the non-formatted data, and do the html formatting on the client-side, maybe using some templates library.

ASP.NET MVC: How to allow some HTML mark-up in Html Encoded content?

Is there some magic existing code in MVC 2 to Html.Encode() strings and allow certain html markup, like paragraph marks and breaks? (coming from a Linq to SQL database field)
A horrible code example to achieve the effect:
Html.Encode(Model.fieldName).Replace("<br />", "<br />")
What would be really nice is to overload something and pass to it an array (or object) full of allowed html tags.
It's not a good idea to create your own whitelist based on regular expressions because you'll likely inadvertently open a security hole for XSS.
From Sanderson's book "Pro ASP.NET MVC3 Framework": "...The only viable mitigation is strict, whitelist-based filtering: use a library like the HTML Agility Pack to ensure the user-supplied markup contains only the tags that you explicitly allow."
Sanderson goes on to supply a link to a site that demonstrates a broad range of XSS techniques that you'd have to test for if you use the regex approach. Check out http://ha.ckers.org/xss.html
There is nothing built in to ASP.NET or MVC for this, but it's not that hard to write your own whitelist-based one with regular expressions and so on. Here's one that Jeff wrote, though it's pretty rough around the edges...
I can't think of anything off the bat but I guess you could write an extension method that allows you to add a paremeter/list of items to allow.
Html.Encode(Mode.fieldName, List<items> Myitems);
It could modify the allowable tags into < etc and then encodes the rest like normal.

French characters are not displaying correctly inside javascript grid

We have translated one of our pages to french and all the html within the page displays flawlessly. That said, there is a javascript table (ext js) and the accented characters are not displaying correctly. The page is encoded UTF-8 in the HTML meta tags, but when I look inside FireBug, I see the following:
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
I'm guessing the problem is related to the ISO-8859-1 having worked its way back in. Does anyone know why the page itself would display fine, but the text inside the javascript component wouldn't? Do you somehow specify the encoding separately for the javascript files?
The Accept-Charset tag gives a set of encodings that are accepted -- if all the data sent is encoded UTF-8, then don't worry about it.
Can you elaborate on exactly what is happening?
You say "javascript table" -- I presume you are constructing an HTML table in JS and placing it in the DOM? Please elaborate, especially w.r.t. any character conversions. Are you building HTML text or building with DOM elements with attributes?
Where does the JS get its data? If with AJAX, have you verified the Encoding for that page?
Does the JS use encode() or decode()? Those don't handle UTF-8 correctly.
EDIT:
Type the URL to the JS code in your browser, and look at "Page Info" to see its encoding. I'll bet it is ISO-8859-1, which would explain the header problems.
Next, check the encoding of the AJAX data. If it's dynamically created you can:
Enable "Show XMLHttpRequests" in FireBug's console,
Load on your base HTML page,
Open the FireBug console tab,
Expand the AJAX GET/POST request and open the Response sub-tab,
Check the Encoding for the data, and fix as needed.
BTW, I'm having similar problems and haven't entirely ironed out the issues (still not sure the source data isn't badly encoded).
It's possible that the ext. JS file strips out unrecognised characters as a security precaution.
The "Accept-Charset" header can be specified in a number of places, including as an attribute in certain HTML elements. Have you performed a search for Accept-Charset (case insensitive) in the offending file?

Resources