read word file with text and picture - c#

i have a word(Office) file. this file content text and picture.
how can read this file and show in <textarea> </textarea>;

The best way to display rich content like word document on UI is through html. You can export your word document to HTML and render it to asp.net UI controls. If you prefer, textarea, you have to implement custom textarea to support images from word-html file.
Also, you can use WebBrowser control to display this word-html file instead of textarea.

I don't believe you can read this into a <textarea> as you ask. (I will watch to see if somebody else shows how, because I want to see that too...) I believe the closest result you will get is to open the document into an <iframe> with the application/msword content type. If you are looking for some flexiblity in this, wrap the space in a <div> and swap out <textarea> for <iframe> at the server when appropriate.

Related

How to parse HTML text and add it to MigraDoc Document

I need to get a text that's being written by a user (in CKEditor HTML), and then add that text to a MigraDoc document, as a paragraph or whatever I need it to be.
My idea was converting the text to an MDDDL document (in memory) and add it to the document. But I don't know if there are any DLLs that permit that behaviour.
So, my question is, can someone give me pointers or advice on how I could make this happen? Should I parse the HMTL text? If so, to what should I parse it? How can I add it afterwards?
Neither PDFsharp nor MigraDoc can parse HTML, so either write your own code or try to find a third-party library (which may not exist yet).
I would probably convert the HTML directly to MigraDoc document objects in memory.
MigraDoc / PDFSharp can't do this.
But, you could use HtmlAgilityPack nuget and then use its htmlDoc.DocumentNode.Descendants() to pull out the pieces of text from html in a flat list kind of a structure, and node.ParentNode.Name to figure out the tag that the text is wrapped in. And then insert the text into your MigraDoc document with something like .AddFormattedText() and apply custom MigraDoc styles to it - i.e. if the parent tag is "strong" then apply a MigraDoc style where Font.Italic = true; etc..

Display same as richtextbox into webbrowser

I am developing chat app in C#,in which I have one richtextbox in which user enters text and "gif" emojis,although animation is not displayed in the richtextbox,but I require that animation to be displayed in to the webbrowser's div element.is there any method which can directly convert the "RTF" of the richtextbox which also includes images to the format which webbrowser's div can display?if yes than please provide me link.If no than please give me any idea regarding how can i achive this.I mean copy whole content of richtextbox to webbrowser's div,which will show animation for no animated images included in richtextbox..
I think what you are looking for is the contenteditable attribute of a div.
If you set the ContentEditable attribute you are able to write html directly to into your browser.
View this page to get more informations about the contenteditable attrbute.
https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_Editable
or check this. maybe this is already what you want: http://jquer.in/helpful-jquery-plugins-for-html5-websites/emojiarea/

Best method or control to display text from a file in an asp.net webpage

This may be a totally newbie question, but here it goes. I have a asp.net web page that I need to display text from a .txt file. I am trying to figure what would be the best control to do this with or the best method. I looked at using an iframe, but this does a very poor job of displaying the text from the file (for instance no word wrap for an iframe). I don't really expect anyone to solve this for me completely, but if you have any suggestions or know of any links to tutorials or explanations where someone has done this, I would be very greatful.
Thanks
You can for example add a Literal control, assign File.ReadAllLines("yourfile.txt") to the Text property and replace \r\n with <br />.
You should just read the text-file in code (using a streamreader for example). Once you have that text, just output it to your web page.
If you're using web forms you could place a label and then set the text of that label.
If you're using MVC you could put it in the ViewBag and then in your view output the value from the ViewBag (or use a custom viewmodel)
You could use a Literal or Label control. Make sure that the control that you use encodes the text in order to avoid XSS vulnerabilities (or encode the text manually if necessary).
It might as well be necessary to substitute line endings with <br/> tags.

Converting HTML to PDF exact replica not shown

I am doing an R&D for converting HTML to PDF.
We have created a page in Asp.net and has placed a CKEditor on it with simple options of selecting Fonts, Font Size, Bond, Italic etc. There is two more text boxes from where user can enter height and width of PDF to be generated. In addition to this we have div which shows preview of the content on the basis of text inserted in Editor. The Div height and width are set at run time, basically with this div we want to show how pdf is going to look like.
We are using wkhtmltopdf exe for generating PDF.
Now my problem is that the PDF being created is not exact replica of content shown in Div, sometimes it show exact content line by line but some times some words move out to next line in PDF
We have tried lot and lot of things to achieve exact result but could not successes any help is appriciable.
One thing you might try is using DOMPDF:
https://code.google.com/p/dompdf/
It's updated pretty frequently and has always given me great results.
Another suggestion would be to create styles specific to the PDF to get the desired result and then have those applied when the PDF is created.
In otherwords if you have a button "generate pdf" have it take all HTML content and then insert PDF specific style tags that you've tested in your PDF generator that makes the rendering the same as the browser. You could do this by just replacing:
</head>
With
<style>STYLES SPECIFIC TO PDF</style>
</head>
Upon creation of the PDF.
PDF rendering in my experience usually requires a few extra rules to make it look like web rending engines.
Hope that helps.

Problems with ActiveReports and RichTextBox

I have a problem ActiveReports 3.0 (VB.NET) with RichTextBox. When I print an RTF text which attribute: "\page" that it must make a BreakPage and need to print more than one page. But the report does not understand this attribute "\page" (BreakPage) and print it on a page.
Alternatively I thought to split the rtf file after the item "\page" and save to the database in more records, RTF file fragments where each row will be displayed in RichTextBox in ActiveReport. The problem is that the RTF file header will only be in first record, but other records will not have headers which will not allow them open in RTB control.
How can I split a RTF or resolve problem with ActiveReports?
Thanks in advance!
Unfortunately, the ActiveReports RichEdit control does not support page breaks.
Maybe you can make the header just a separate static RTF that you add to a group header? I'd have to see your report and what you're trying to accomplish to do more.
Scott Willeke
GrapeCity inc.

Categories