[RESOLVED] Copy text from a webpage and keep formatting
Hi,
I want to put some kind of text editor on my website which allows the user to manipulate the formatting of text.
I would also like it to be possible for a user to copy/paste text from an existing webpage and it keep the formatting i.e. markup tags, font weight, bullet points.
I just dont know hoe to go about this but the information must be there as when you copy from a web page into ms Word it keeps the format.
Re: Copy text from a webpage and keep formatting
You just need a Rich text editor for your site. A personal favourite of mine is TinyMCE but there are many many more if you google Rich Text Editor or WYSIWYG editor
Re: Copy text from a webpage and keep formatting
I personally like FCKEditor, which has now changed name to just CKEditor.
http://ckeditor.com/
Gary
Re: Copy text from a webpage and keep formatting
Ok I chose to use FreeTextBox which accepts the html fine, now I need to store the contents in a way that will enable me to generate generate a PDF. I need to strip out all the HTML markup that is not required nd then produce a document that keeps has paragraphs, line breaks, bullet points, bold text and headings as originally specified in the html. I have had a look at MigraDoc for creating PDFs but it looks like it is the stripping out of unwanted html and formatting based on kept markup where I am going to struggle. I have considered making a word doc rather than pdf then making the pdf from the word doc, this may allow me to only have to srip out the unwanted html.
I would welcome any suggestions as to how to achieve this.
Re: Copy text from a webpage and keep formatting
Hey,
How about the iTextSharp library:
http://sourceforge.net/projects/itextsharp/
If you search these forums, you will find examples of how to use it.
Why are you stripping out the html? Why not print the HTML directly to the PDF? If you are looking to strip out the HTML, then have a look at the HtmlAgilityPack:
http://htmlagilitypack.codeplex.com/
This should be able to help you.
Gary
Re: Copy text from a webpage and keep formatting
The WebBrowser has a built in mini-editor inside it. It is not as advanced as a full fledged text editor or one of those advanced html editors, but see if it is sufficient for your needs.
Add a WebBrowser control to your form and the following code:
vb.net Code:
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
If WebBrowser1.ReadyState = WebBrowserReadyState.Complete Then WebBrowser1.Document.ExecCommand("EditMode", False, Nothing)
End Sub
Re: Copy text from a webpage and keep formatting
Pradeep,
Let me see if I have this right...
You are suggesting that you use a System.Windows.Forms.WebBrowser control in an ASP.net WebPage to allow the editing of HTML?
Will that even work?!?
Gary
Re: Copy text from a webpage and keep formatting
My bad... :(
I was thinking about VB.NET desktop application while writing that post.
Re: Copy text from a webpage and keep formatting
Quote:
Originally Posted by
Pradeep1210
My bad... :(
I was thinking about VB.NET desktop application while writing that post.
Cool, that is what I thought. Either that, or you were being VERY clever, and I wanted to know more :thumb:
Gary