How to read a Doc or PDF file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Shayer

    #1

    How to read a Doc or PDF file

    Hello All

    I am trying to read a MSDoc file and PDF file using Streamreader and then
    display the content into a richtext box. But cant do that.

    Anyone can pls help me out

    Thanks

    Shayer


  • phoenix

    #2
    Re: How to read a Doc or PDF file

    Docs and pdfs have special layouts. You'll need specific readers for that.
    You can open your Doc using word then selecting all text and copy it to your
    richtextbox. For pdfs I never tried it but I guess there's something
    similar.

    Yves

    "Shayer" <shayer009@hotm ail.com> schreef in bericht
    news:uDGtBjnzDH A.2452@tk2msftn gp13.phx.gbl...[color=blue]
    > Hello All
    >
    > I am trying to read a MSDoc file and PDF file using Streamreader and then
    > display the content into a richtext box. But cant do that.
    >
    > Anyone can pls help me out
    >
    > Thanks
    >
    > Shayer
    >
    >[/color]


    Comment

    • Shayer

      #3
      Re: How to read a Doc or PDF file

      Thanks for ur advice

      But how can i open the doc and read the content and display in the
      richtextbox

      How can u do that

      ANy sample code will be helpful

      Thanks

      regards
      Shayer
      "phoenix" <patient0@skyne tWORK.be> wrote in message
      news:OOtEsPszDH A.1100@TK2MSFTN GP10.phx.gbl...[color=blue]
      > Docs and pdfs have special layouts. You'll need specific readers for that.
      > You can open your Doc using word then selecting all text and copy it to[/color]
      your[color=blue]
      > richtextbox. For pdfs I never tried it but I guess there's something
      > similar.
      >
      > Yves
      >
      > "Shayer" <shayer009@hotm ail.com> schreef in bericht
      > news:uDGtBjnzDH A.2452@tk2msftn gp13.phx.gbl...[color=green]
      > > Hello All
      > >
      > > I am trying to read a MSDoc file and PDF file using Streamreader and[/color][/color]
      then[color=blue][color=green]
      > > display the content into a richtext box. But cant do that.
      > >
      > > Anyone can pls help me out
      > >
      > > Thanks
      > >
      > > Shayer
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • phoenix

        #4
        Re: How to read a Doc or PDF file

        "Shayer" <shayer009@hotm ail.com> schreef in bericht
        news:e0YpyVszDH A.1856@TK2MSFTN GP09.phx.gbl...[color=blue]
        > Thanks for ur advice
        >
        > But how can i open the doc and read the content and display in the
        > richtextbox
        >
        > How can u do that
        >
        > ANy sample code will be helpful
        >
        > Thanks
        >
        > regards
        > Shayer
        > "phoenix" <patient0@skyne tWORK.be> wrote in message
        > news:OOtEsPszDH A.1100@TK2MSFTN GP10.phx.gbl...[color=green]
        > > Docs and pdfs have special layouts. You'll need specific readers for[/color][/color]
        that.[color=blue][color=green]
        > > You can open your Doc using word then selecting all text and copy it to[/color]
        > your[color=green]
        > > richtextbox. For pdfs I never tried it but I guess there's something
        > > similar.
        > >
        > > Yves
        > >
        > > "Shayer" <shayer009@hotm ail.com> schreef in bericht
        > > news:uDGtBjnzDH A.2452@tk2msftn gp13.phx.gbl...[color=darkred]
        > > > Hello All
        > > >
        > > > I am trying to read a MSDoc file and PDF file using Streamreader and[/color][/color]
        > then[color=green][color=darkred]
        > > > display the content into a richtext box. But cant do that.
        > > >
        > > > Anyone can pls help me out
        > > >
        > > > Thanks
        > > >
        > > > Shayer
        > > >[/color][/color][/color]

        First of all add a reference to the word library. It should be located under
        'COM' under 'Microsoft Word x.xx Object Library' (with x.xx your version).

        Then the following code should do the trick :

        /*************** *************** *************** ****/

        object filename = @"c:\test.do c";
        object save = false;
        object oMissing = System.Reflecti on.Missing.Valu e;

        Word._Applicati on oWord;
        Word._Document oDoc;
        oWord = new Word.Applicatio n();
        oWord.Visible = false;

        // Open word document
        // different versions of word may have more or less oMissings
        oDoc = oWord.Documents .Open(ref filename, ref oMissing, ref oMissing,
        ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
        ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
        ref oMissing, ref oMissing, ref oMissing);

        // Select everything
        oDoc.Select();

        // Copy everything
        oWord.Selection .Copy();

        // Clean up the RTB
        richTextBox1.Te xt = "";
        // Paste the entire text with format
        richTextBox1.Pa ste();

        // Close word
        oDoc.Close(ref save, ref oMissing, ref oMissing);
        oWord.Quit(ref save, ref oMissing, ref oMissing);

        /*************** *************** *************** ****/

        HTH

        Yves


        Comment

        • phoenix

          #5
          Re: How to read a Doc or PDF file


          "phoenix" <patient0@skyne tWORK.be> schreef in bericht
          news:Oz4UQGtzDH A.1708@TK2MSFTN GP12.phx.gbl...[color=blue]
          > "Shayer" <shayer009@hotm ail.com> schreef in bericht
          > news:e0YpyVszDH A.1856@TK2MSFTN GP09.phx.gbl...[color=green]
          > > Thanks for ur advice
          > >
          > > But how can i open the doc and read the content and display in the
          > > richtextbox
          > >
          > > How can u do that
          > >
          > > ANy sample code will be helpful
          > >
          > > Thanks
          > >
          > > regards
          > > Shayer
          > > "phoenix" <patient0@skyne tWORK.be> wrote in message
          > > news:OOtEsPszDH A.1100@TK2MSFTN GP10.phx.gbl...[color=darkred]
          > > > Docs and pdfs have special layouts. You'll need specific readers for[/color][/color]
          > that.[color=green][color=darkred]
          > > > You can open your Doc using word then selecting all text and copy it[/color][/color][/color]
          to[color=blue][color=green]
          > > your[color=darkred]
          > > > richtextbox. For pdfs I never tried it but I guess there's something
          > > > similar.
          > > >
          > > > Yves
          > > >
          > > > "Shayer" <shayer009@hotm ail.com> schreef in bericht
          > > > news:uDGtBjnzDH A.2452@tk2msftn gp13.phx.gbl...
          > > > > Hello All
          > > > >
          > > > > I am trying to read a MSDoc file and PDF file using Streamreader and[/color]
          > > then[color=darkred]
          > > > > display the content into a richtext box. But cant do that.
          > > > >
          > > > > Anyone can pls help me out
          > > > >
          > > > > Thanks
          > > > >
          > > > > Shayer
          > > > >[/color][/color]
          >
          > First of all add a reference to the word library. It should be located[/color]
          under[color=blue]
          > 'COM' under 'Microsoft Word x.xx Object Library' (with x.xx your version).
          >
          > Then the following code should do the trick :
          >
          > /*************** *************** *************** ****/
          >
          > object filename = @"c:\test.do c";
          > object save = false;
          > object oMissing = System.Reflecti on.Missing.Valu e;
          >
          > Word._Applicati on oWord;
          > Word._Document oDoc;
          > oWord = new Word.Applicatio n();
          > oWord.Visible = false;
          >
          > // Open word document
          > // different versions of word may have more or less oMissings
          > oDoc = oWord.Documents .Open(ref filename, ref oMissing, ref oMissing,
          > ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
          > ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
          > ref oMissing, ref oMissing, ref oMissing);
          >
          > // Select everything
          > oDoc.Select();
          >
          > // Copy everything
          > oWord.Selection .Copy();
          >
          > // Clean up the RTB
          > richTextBox1.Te xt = "";
          > // Paste the entire text with format
          > richTextBox1.Pa ste();
          >
          > // Close word
          > oDoc.Close(ref save, ref oMissing, ref oMissing);
          > oWord.Quit(ref save, ref oMissing, ref oMissing);
          >
          > /*************** *************** *************** ****/
          >
          > HTH
          >
          > Yves
          >[/color]

          If the document is rather large you may think about opening it the same way
          as above but saving it immediatly in rtf format. You can then open it
          through your richtextbox. After you made the changes you can always use the
          same way to overwrite the original doc if that's what you're planning.

          Yves


          Comment

          • Shayer

            #6
            Re: How to read a Doc or PDF file

            Thanks Mate

            Its a perfect solution. Thanks a lot

            I am still toying the idea how can i read the content off PDF

            Thanks once again

            regards

            Shayer


            "phoenix" <patient0@skyne tWORK.be> wrote in message
            news:#aCZ9KtzDH A.1740@TK2MSFTN GP12.phx.gbl...[color=blue]
            >
            > "phoenix" <patient0@skyne tWORK.be> schreef in bericht
            > news:Oz4UQGtzDH A.1708@TK2MSFTN GP12.phx.gbl...[color=green]
            > > "Shayer" <shayer009@hotm ail.com> schreef in bericht
            > > news:e0YpyVszDH A.1856@TK2MSFTN GP09.phx.gbl...[color=darkred]
            > > > Thanks for ur advice
            > > >
            > > > But how can i open the doc and read the content and display in the
            > > > richtextbox
            > > >
            > > > How can u do that
            > > >
            > > > ANy sample code will be helpful
            > > >
            > > > Thanks
            > > >
            > > > regards
            > > > Shayer
            > > > "phoenix" <patient0@skyne tWORK.be> wrote in message
            > > > news:OOtEsPszDH A.1100@TK2MSFTN GP10.phx.gbl...
            > > > > Docs and pdfs have special layouts. You'll need specific readers for[/color]
            > > that.[color=darkred]
            > > > > You can open your Doc using word then selecting all text and copy it[/color][/color]
            > to[color=green][color=darkred]
            > > > your
            > > > > richtextbox. For pdfs I never tried it but I guess there's something
            > > > > similar.
            > > > >
            > > > > Yves
            > > > >
            > > > > "Shayer" <shayer009@hotm ail.com> schreef in bericht
            > > > > news:uDGtBjnzDH A.2452@tk2msftn gp13.phx.gbl...
            > > > > > Hello All
            > > > > >
            > > > > > I am trying to read a MSDoc file and PDF file using Streamreader[/color][/color][/color]
            and[color=blue][color=green][color=darkred]
            > > > then
            > > > > > display the content into a richtext box. But cant do that.
            > > > > >
            > > > > > Anyone can pls help me out
            > > > > >
            > > > > > Thanks
            > > > > >
            > > > > > Shayer
            > > > > >[/color]
            > >
            > > First of all add a reference to the word library. It should be located[/color]
            > under[color=green]
            > > 'COM' under 'Microsoft Word x.xx Object Library' (with x.xx your[/color][/color]
            version).[color=blue][color=green]
            > >
            > > Then the following code should do the trick :
            > >
            > > /*************** *************** *************** ****/
            > >
            > > object filename = @"c:\test.do c";
            > > object save = false;
            > > object oMissing = System.Reflecti on.Missing.Valu e;
            > >
            > > Word._Applicati on oWord;
            > > Word._Document oDoc;
            > > oWord = new Word.Applicatio n();
            > > oWord.Visible = false;
            > >
            > > // Open word document
            > > // different versions of word may have more or less oMissings
            > > oDoc = oWord.Documents .Open(ref filename, ref oMissing, ref oMissing,
            > > ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
            > > ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,
            > > ref oMissing, ref oMissing, ref oMissing);
            > >
            > > // Select everything
            > > oDoc.Select();
            > >
            > > // Copy everything
            > > oWord.Selection .Copy();
            > >
            > > // Clean up the RTB
            > > richTextBox1.Te xt = "";
            > > // Paste the entire text with format
            > > richTextBox1.Pa ste();
            > >
            > > // Close word
            > > oDoc.Close(ref save, ref oMissing, ref oMissing);
            > > oWord.Quit(ref save, ref oMissing, ref oMissing);
            > >
            > > /*************** *************** *************** ****/
            > >
            > > HTH
            > >
            > > Yves
            > >[/color]
            >
            > If the document is rather large you may think about opening it the same[/color]
            way[color=blue]
            > as above but saving it immediatly in rtf format. You can then open it
            > through your richtextbox. After you made the changes you can always use[/color]
            the[color=blue]
            > same way to overwrite the original doc if that's what you're planning.
            >
            > Yves
            >
            >[/color]


            Comment

            Working...