Results 1 to 9 of 9

Thread: [RESOLVED] Copy text from a webpage and keep formatting

  1. #1

    Thread Starter
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Resolved [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.

  2. #2
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092

    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

  3. #3
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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

  4. #4

    Thread Starter
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    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.

  5. #5
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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

  6. #6
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    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:
    1. Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
    2.     If WebBrowser1.ReadyState = WebBrowserReadyState.Complete Then WebBrowser1.Document.ExecCommand("EditMode", False, Nothing)
    3. End Sub
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  7. #7
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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

  8. #8
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Copy text from a webpage and keep formatting

    My bad...

    I was thinking about VB.NET desktop application while writing that post.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  9. #9
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Copy text from a webpage and keep formatting

    Quote Originally Posted by Pradeep1210 View Post
    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

    Gary

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width