Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

ConvertDoc2Rtf - displaying graphics in Richedit component?

Posted on 2006-04-11
23
Medium Priority
?
622 Views
Last Modified: 2013-11-22
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;
0
Comment
Question by:myleseven
  • 12
  • 11
23 Comments
 
LVL 8

Expert Comment

by:RickJ
ID: 16433536
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
 

Author Comment

by:myleseven
ID: 16442633
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
 
LVL 8

Expert Comment

by:RickJ
ID: 16558718
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:myleseven
ID: 16558841
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
 
LVL 8

Expert Comment

by:RickJ
ID: 16558851
No problem. In the mean time I might install rxRichEdit and play.
0
 

Author Comment

by:myleseven
ID: 16559398
great thanks :)!
0
 

Author Comment

by:myleseven
ID: 16705372
Hey I am back :)
How is it going?
0
 
LVL 8

Expert Comment

by:RickJ
ID: 16804473
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
 

Author Comment

by:myleseven
ID: 16812251
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
 
LVL 8

Expert Comment

by:RickJ
ID: 16812850
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
 

Author Comment

by:myleseven
ID: 16848490
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
 
LVL 8

Expert Comment

by:RickJ
ID: 16950948
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
 
LVL 8

Expert Comment

by:RickJ
ID: 16950979
Just had a closer look and can confirm that I downloaded the following..
JCL 1.96
JVCL 3.00
0
 

Author Comment

by:myleseven
ID: 16966245
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
 
LVL 8

Expert Comment

by:RickJ
ID: 16967654
OK.
0
 

Author Comment

by:myleseven
ID: 16997981
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
 
LVL 8

Expert Comment

by:RickJ
ID: 16998493
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
 

Author Comment

by:myleseven
ID: 16998628
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
 
LVL 8

Expert Comment

by:RickJ
ID: 16998881
Hello Myles,
You need to put this in your form create event.

Editor.RegisterMSTextConverters;

It does as it suggests.

Hope this helps.
Rick.
0
 

Author Comment

by:myleseven
ID: 17005926
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
 
LVL 8

Accepted Solution

by:
RickJ earned 1000 total points
ID: 17006280
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
 

Author Comment

by:myleseven
ID: 17006317
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
 

Author Comment

by:myleseven
ID: 17006357
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

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question