ConvertDoc2Rtf - displaying graphics in Richedit component?

hi there,
I have tried out the function: ConvertDoc2Rtf(see below)
http://www.swissdelphicenter.ch/torry/showcode.php?id=722
http://www.swissdelphicenter.ch/torry/showcomment.php?id=722&detail=1478

it works well, however if the document has a graphic in it then the graphic will not be displayed in the Richedit component. However, the graphic will get displayed in Microsoft word.
How can I display a graphic in a RichEdit component?

function ConvertDoc2Rtf(var FileName: string) : Boolean;
var
  oWord: OleVariant;
  oDoc: OleVariant;
begin
  Result := False;
  try
    oWord := GetActiveOleObject('Word.Application');
  except
    oWord := CreateOleObject('Word.Application');
  end;
  oWord.Documents.Open(FileName);
  oDoc  := oWord.ActiveDocument;
  FileName := ChangeFileExt(FileName, '.rtf');
  //oDoc.SaveAs(FileName);
  oDoc.SaveAs(FileName,wdFormatRTF);
  oWord.ActiveDocument.Close(wdDoNotSaveChanges, EmptyParam, EmptyParam);
  oWord.Quit(EmptyParam, EmptyParam, EmptyParam);
  oDoc := VarNull;
  oWord := VarNull;
  Result := True;
end;
mylesevenAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RickJCommented:
I dont think you can display an image in the base RichEdit component.
I recently asked a sort of similar question and was given a few links to some great (some free!!) components.

http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_21798960.html

Also checkout the Jedi VCL page at sourceforge. Which is not listed in the above link.
http://homepages.borland.com/jedi/jvcl/

All of the Richedit components are really powerful.
Hope this helps.





0
mylesevenAuthor Commented:
Thanks for your help RickJ,
I finally managed to find and install rxRichEdit for Delphi 7 and this is doing what I would like.

http://www.delphipages.com/threads/thread.cfm?ID=94460&G=94392
http://delphi.icm.edu.pl/ftp/d70free/Rx275D7.zip


Just wondering though how do I display headers etc in this component?
Are there any tutorials around on how to use it?


you might also be interested in another question that I am asking

http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_21812292.html

kind regards
Myles
0
RickJCommented:
Hello myleseven,
Sorry for the delayed reply. I have been on an extended easter break.
I ended up using the Jedi vcl rich edit component. It is able to load .doc files directly. I believe it has its own conversion routines.
This may be a better component for your use.
If you want I could install the rxRichEdit and try and solve your issues?
Or you may have already fixed your issues?

Once again sorry for the delay.
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

mylesevenAuthor Commented:
Hi RickJ
No my question is still not resolved. And it is something that is crucial for me to solve.
I am interested to hear that the Jedi VCL rich edit is able to load .doc files directly.  I did have a look at the jedi components but was not sure which ones to download and install.

At the present moment I need to spend time on another small project but that should be finished in about a week.
I would like to keep this question open as it will be the next project that I move onto and is critical for our company....

do you mind if I hold on for a moment with my replies?

regards
Myles
0
RickJCommented:
No problem. In the mean time I might install rxRichEdit and play.
0
mylesevenAuthor Commented:
great thanks :)!
0
mylesevenAuthor Commented:
Hey I am back :)
How is it going?
0
RickJCommented:
Hello myleseven,
I must of missed your email, I was just checking and saw your comment.
I played a little with the rxRichEdit control, but found the Jedi one to suit me better.

Maybe if you explain exactly what your application needs to do I will give my opinon of what component would be best.

Thanks.
0
mylesevenAuthor Commented:
Hey Rick,
Happy to hear from you again.
Basically I have built a simple text editing program. Similar to word pad.
The user can only do a limited set of basic funcitons. you know the standard things. Open, Save Print with a few basic text formatting features thrown in (bold, italic, font type etc). Nothing complicated at all.
At the moment though I am using a Rich Edit component. It does the job very well, but because I cannot open .doc files into my RichEdit component, I therefore choose not to display files that end in .doc in my Open File dialog box. THus if a user has a .doc file that they would like to open and edit: 1. IT will look like it does not exist even when it does; 2. Even if they could see it when they open the .doc file only garbage will be displayed in the RichEdit component.
Some of my users have complained about this and fair enough. SO I would like to give them the ability to open their .doc files into my Text editing program and allow them to edit the doecument (using only the controls in my program) as if the would had they opened it in Word. I would prefer not to change the file extension to .rtf or anything as then existing formatting might be lost (eg tables, pics etc). My uesrs also might not have Word installed so automation is probably out of the question...

What do you suggest?

regards
Myles
0
RickJCommented:
I would probably use the Jedi components.
In the download for the components their is a fully functional text editing program as an example.
I have used this as a basis for my application, and without to many changes it works perfectly.
It loads a variety of fomats including .doc. It has all the things that you have suggested plus a lot more.
For not much more effort than downloading and installing, you may have an answer to all your problems.

Jedi is also not just RichEdit, it contains just about every component you could think of.  
0
mylesevenAuthor Commented:
Hey Rich
I had a look at the Mega Demo app and saw the demo using jvRichedit it looks like the one I need.
I downloaded JVCL320CompleteJCL197-Build2172
is that the one I need.
Having a bit of trouble installing it at the moment, but will have another go later.
Is this the one that you installed?

regards
M
0
RickJCommented:
Sorry again Myles,
My spam blocker seems to be catching some of these :( !!
I had some problems with the very latest download (not sure what version), so I downloaded a previous stable version.
I dont know the exact build but the help says V3.0.

How is it going? Did you get it installed correctly?
I will watch for your reply.
0
RickJCommented:
Just had a closer look and can confirm that I downloaded the following..
JCL 1.96
JVCL 3.00
0
mylesevenAuthor Commented:
Thanks for that Rick,
No I havn't been able to install it yet. But I will try the ones that you suggessted.
I will try and come back to you next week with an answer

cheers
Myles :)
0
RickJCommented:
OK.
0
mylesevenAuthor Commented:
Hi Rick,
I have managed to install the JCL and JVCL Jedi components, thanks heaps for that youhave now increased my library 10 fold!
According to the Megademo I need to use the jvRichEdit. But when I drop this component onto the form and try and load a doc file into it I get garbage in the editor.
I then opened up the jvRichedit example program that comes with everything and when I looked at the code I could not see what they are doing differently.
It appears that we are using the same code
Editor.lines.loadfromfile('myfile.doc');
Is there something I am not doing?
Have you been able to load a .doc file into the jvRichEdit component

cheers
Myles
0
RickJCommented:
You need not install all components, just RichEdit and dependant libraries if you like.
If you look in the examples directory there is a JvRichEdit demo, this may be different than the mega demo.

The only things I would make sure of are that you have plaintext set to False and streammode set to sfDefault.
Yes I am loading .doc all the time, and it is working OK.

Maybe post the contents of the pas + dfm files and I will test for you.

Rick.
0
mylesevenAuthor Commented:
The suggestions that you mentioned are all ok, maybe you can see something I can't. Here is the code:

unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, JvExStdCtrls, JvRichEdit, ComCtrls, ShellCtrls;

type
  TForm2 = class(TForm)
    ShellTreeView1: TShellTreeView;
    Label2: TLabel;
    Label1: TLabel;
    Edit2: TEdit;
    Edit1: TEdit;
    ShellListView1: TShellListView;
    Editor: TJvRichEdit;
    Button5: TButton;
    Button1: TButton;
    procedure ShellTreeView1Click(Sender: TObject);
    procedure ShellListView1Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.ShellTreeView1Click(Sender: TObject);
begin
  Edit1.text := ShellTreeView1.Path;
end;

procedure TForm2.ShellListView1Click(Sender: TObject);
begin
  Edit2.text := ShellListView1.selectedFolder.PathName;
end;

procedure TForm2.Button5Click(Sender: TObject);
var
  sTemp : string;
begin
  sTemp := shellListview1.SelectedFolder.PathName;
  //RichEdit1.Lines.LoadFromFile(sTemp);
  Editor.Lines.LoadFromFile(sTemp);
end;

procedure TForm2.Button1Click(Sender: TObject);
begin
  close;
end;

end.

//-------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------
Here is the form

object Form2: TForm2
  Left = 108
  Top = 114
  Width = 870
  Height = 640
  Caption = 'Form2'
  Color = clBtnFace
  Font.Charset = ANSI_CHARSET
  Font.Color = clWindowText
  Font.Height = -19
  Font.Name = 'Arial'
  Font.Style = []
  OldCreateOrder = False
  WindowState = wsMaximized
  PixelsPerInch = 96
  TextHeight = 22
  object Label2: TLabel
    Left = 16
    Top = 80
    Width = 97
    Height = 22
    Caption = 'Save folder'
  end
  object Label1: TLabel
    Left = 8
    Top = 120
    Width = 134
    Height = 22
    Caption = 'Save File Name'
  end
  object ShellTreeView1: TShellTreeView
    Left = 8
    Top = 152
    Width = 233
    Height = 289
    ObjectTypes = [otFolders]
    Root = 'rfPersonal'
    ShellListView = ShellListView1
    UseShellImages = True
    AutoRefresh = False
    Font.Charset = ANSI_CHARSET
    Font.Color = clWindowText
    Font.Height = -13
    Font.Name = 'Arial'
    Font.Style = []
    Indent = 19
    ParentColor = False
    ParentFont = False
    RightClickSelect = True
    ShowRoot = False
    TabOrder = 0
    OnClick = ShellTreeView1Click
  end
  object Edit2: TEdit
    Left = 144
    Top = 112
    Width = 438
    Height = 30
    TabOrder = 1
  end
  object Edit1: TEdit
    Left = 144
    Top = 72
    Width = 446
    Height = 30
    TabOrder = 2
  end
  object ShellListView1: TShellListView
    Left = 245
    Top = 152
    Width = 353
    Height = 297
    ObjectTypes = [otFolders, otNonFolders]
    Root = 'rfPersonal'
    ShellTreeView = ShellTreeView1
    Sorted = True
    OnClick = ShellListView1Click
    ReadOnly = False
    Font.Charset = ANSI_CHARSET
    Font.Color = clWindowText
    Font.Height = -13
    Font.Name = 'Arial'
    Font.Style = []
    HideSelection = False
    ParentFont = False
    TabOrder = 3
    ViewStyle = vsReport
  end
  object Editor: TJvRichEdit
    Left = 624
    Top = 152
    Width = 505
    Height = 753
    TabOrder = 4
  end
  object Button5: TButton
    Left = 624
    Top = 104
    Width = 201
    Height = 41
    Caption = 'Open a file'
    TabOrder = 5
    OnClick = Button5Click
  end
  object Button1: TButton
    Left = 623
    Top = 48
    Width = 202
    Height = 49
    Caption = 'close'
    TabOrder = 6
    OnClick = Button1Click
  end
end
0
RickJCommented:
Hello Myles,
You need to put this in your form create event.

Editor.RegisterMSTextConverters;

It does as it suggests.

Hope this helps.
Rick.
0
mylesevenAuthor Commented:
Hi Rick,
THanks that worked great!
Quick question though, does this mean that I need to have MSWord installed for the component to work as I see that the code for RegisterMSTextConverters relies on a Microsoft shared reg key

what do you think?
Myles
0
RickJCommented:
No you dont have to have MSOffice installed.
Just download oconvpck.exe and distribute it with your app. Get it from one of these links.

http://support.microsoft.com/support/kb/articles/q212/2/65.asp
http://www.microsoft.com/office/ork/2003/tools/BoxA07.htm

I have tested this with a clean OS install. (No Office ever installed) and it worked fine.

Rick.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mylesevenAuthor Commented:
ok thanks heaps for that Rick and thanks for all your help, you have been very patient with me:)
The points are yours.
YOu also might know how to help me with a couple of other issues related to the jvRichEdit component. I have posted a new question at:

http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_21902876.html

thanks again
Myles :)
0
mylesevenAuthor Commented:
Hi Rick,
I see that there is a licence agreement with that oconvpck.exe.
As we are a commercial enterprise I am not sure if it is legal for our software to install that .exe on our customers computers if they don't already have office.
It appears to work ok if you have office installed without needing to install that .exe
I wonder did you try running jvRichEdit on a clean OS with out office?
What happened when you opened a .doc?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.