Trouble displaying MS Word html file in Asp.Net Literal Control - asp.net

When I display an html file that was created in MS Word, it doesn't render correctly in the ASP Literal control. It seems to have trouble showing tabs, dashes, bullets, etc. Is there something I can do to make this work?

Some characters from MSWord will never appear correct: tabs, bullets, dashes. You could use XL instead of Word and create a macro that changes the bullets to • or dashes to −. I dont think tabs have an html equivilent.
Others characters (international) can only be shown if both your ascx and aspx are both UTF-8 encoded.

Related

Convert html tagged text to string for a pdf itext7

I am working on a project in asp.net MVC which involves printing various information that the user enters previously.
I use the TinyMCE for comment type fields.
As we know Tiny allows you to format text using different types of fonts, adding bold words, etc.
The string it produces will have tags that allow reading the style chosen for the word or phrase in HTML.
I use Itext7 to produce pdfs, when I print the fields I mentioned above, obviously all the HTML tags are shown, for example:
<p> Hello World! </p>
Is there a way to tell Itext7 that when these tags are present, it must use an associated style for that tag?
I created "Hello World" here and used bold, italic and underline. Copy the source code via "Tools" and just use the following code to convert it via iText7:
String htmlString = "<p><span style=\"text-decoration: underline;\"><em><strong>Hello World</strong></em></span></p>";
HtmlConverter.convertToPdf(htmlString, new PdfWriter(destinationFolder + "test.pdf"));
The resultanting PDF:

Export Superscript text to worddoc from HTML

In my asp.net website I have a HTML page which contains some words with Superscript, for example the HTML representation is as below...
ABC<sup>def</sup>
when it is rendered in browser it appears like this : ABCdef
I have a export feature which export the HTML document to a word document. When I am exporting it is being exported as ABC<sup>def</sup> in the worddoc.
I have been trying to do it using some kind of regex html = html.Replace("<sup>", "\"");
but that doesn't help.
Can anybody please help me how would I make it appear as ABCdef in my word document too using asp.net?
This is an older question but I've been trying to do the same thing in reverse. The problem is with how Word formats and defines its super and subscripts.
There are no tags that Word used to define super and subscripts, it uses relative positioning and font-size declarations to generate symbols that look like super and subscripts.
Unfortunately there is no reliable regex to turn Word's positioning into super/subscripts, and there is no way to regex a document with those tags to make Word recognize them.

Display Word Document inside ASP.Net page

I want to display a word Document, which is sitting on my IIS. I want to display the whole document as is, inside a iFrame on my aspx page.
I know I can use MS Word Libs, but I cannot install Word on Server where application will be hosted, (Correct me if I am wrong: I cannot use just dlls without installing MS Word on Server).
How can I display the word document in my iFrame?
Probably the easiest way would be to include the Google Docs Viewer.
Other ways could be to use Aspose.Words (commercial) to convert Word to PDF and then use Aspose.Pdf.Kit to convert PDF to images and then display the images online.
PowerTools for Open XML contains an open source, free implementation of a conversion from DOCX to HTML formatted with CSS. The module HtmlConverter.cs supports all paragraph, character, and table styles, fonts and text formatting, numbered and bulleted lists, images, and more. See http://bit.ly/1bclyg9

Visual Studio inserting indents as spaces to html output

I am using Visual Studio 2010 for an MVC website project. I have an big problem and dont know hot to solve it. When i am looking to the output of html in firebug indents in my aspx and ascx files are outputed as space in same places. I think its about line ending of files but i am not sure how to fix them. I am adding some pictures about problem.
When i am adding a breakpoint it also add red background to spaces (this is problem) I try to delete spaces after hit ctrl+k d same problem happen.
If i delete all indents make page 1 line without spaces output is fine but it not a solution.
ASPX/ASCX engine emits literal content within markup as is i.e if your file has spaces or tabs for indentation then they will be output as is. You can use Tools->Options for keeping tabs (instead of space) for indents - you can change for all languages or say only for HTML. VS 2010 has a great extension Productivity Power Tools that will (apart from other things) warn you if your file has tabs & space mix and allows you to choose either tabs or spaces.
Now as a better solution, you can use HttpModule to remove whitespace from your response - see http://madskristensen.net/post/A-whitespace-removal-HTTP-module-for-ASPNET-20.aspx

Response.WriteFile("mymenu.aspx") Bug?

I'm using Response.WriteFile("mymenu.aspx") to write a plain text file out to an area in a MasterPage. Unfortunately it's also printing out an unknown character represented by the square character. The contents of the menu file are as followings:
<ul>
<li>Accounts</li>
</ul>
The square character is what is causing my menu to display incorrectly, pushing it down about 20 pixels. I tested putting just the HTML in the master page instead of including the file and it works fine which mean it must be down to the Response.WriteFile function. I don't suppose anyone else has encountered this problem?
EDIT: I tried the following as well, just to really make sure I wasn't doing anything stupid and that the file didn't contain anything dodgy.
<%
Dim tw As New System.IO.StreamReader(Server.MapPath("menu.aspx"))
For Each s As String In tw.ReadToEnd
Response.Write(s)
Next
%>
It worked. But that still doesn't explain Response.WriteFile behaviour.
Have a look at your text file in an editor that will show all characters including carriage returns, line feeds etc. (Notepad++ is my choice). File may have an unusual eof marker or other encoding issue from the software that created the file.
This sounds like a character encoding issue. Is this file in the same encoding as the page your using it from?
Edit
Open the file up in a hex editor make sure there are no weird characters in there.
I tested your code and it rendered correctly for me.
I have seen ASP.NET alter incoming XML strings in WebMethods before. Save the text to a file on disk before you Response.Write it to compare. Check your CSS for your LI style.

Resources