Solved

Convert MS-Word Doc Into Image

Posted on 2003-11-30
10
891 Views
Last Modified: 2009-03-08
Hi everybody

I was wandering if anyone could help?, I have created a word document AND I want to convert this document intointo any type of image's

(try
           to convert using OLE
 else
           any else method)

Please Help me!!!!

Thank you very much



0
Comment
Question by:Aziz_xxx_Habbib
10 Comments
 
LVL 2

Expert Comment

by:odissey1
ID: 9847958
Hi Aziz_xxx_Habbib,

1. Do you want to export just just first page or multiple pages?
2. Do you create *.doc programmatically? How? Could it be easyer to export image directly (without Word)?

Regards,
odissey1
0
 
LVL 2

Expert Comment

by:TheLeader
ID: 9848207
why don't you convert it to pdf & then to bmp !
0
 
LVL 7

Expert Comment

by:sftweng
ID: 9848628
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:Aziz_xxx_Habbib
ID: 9849725
Hi Mr.Odissey1

1. I want to export both method (first or multiple pages).....

2. I create *.doc using MS-Word but I want to export it to image using Delphi



Regards,
Aziz_xxx_Habbib

0
 
LVL 6

Accepted Solution

by:
Sergio_Hdez earned 500 total points
ID: 9964073
I do it from time to time using OLE containers:

A) Create a TmpForm like this one:

  TmpForm:= TForm.create(Application.MainForm);
  TmpForm.WindowState:= wsMaximized;
  TmpForm.Color:= clWhite;

B) Then place a BIG ole container on top like this one:

  Ole:= TOleContainer.create(TmpForm);
  Ole.Color:= clWhite;
  Ole.Parent:= TmpForm;
  Ole.SizeMode:= smStretch;
  Ole.AutoActivate:= aaManual;
  Ole.AllowInPlace:= false;
  Ole.Align:= alClient;
  Ole.AutoVerbMenu:= false;
  Ole.BorderStyle:= bsNone;

C) Now load the DOC into the OLE, if you one the user to select it, use this:

  Cur:= Screen.Cursor;
  Screen.Cursor:= crHourGlass;
  Ole.InsertObjectDialog;
  Screen.Cursor:= Cur;

But if you one, you also can load it from code, from a TMemoryStream (a Blob field of a databse saved to stream, for instance):

Ole.LoadFromStream(Tmp);

or from a file:

Ole.LoadFromFile(FileName);

D) Now you can take a "photo" of the DOC by using something like it:

  Foto:= TPicture.create;
  //Show-up the form...
  TmpForm.Visible:= true;
  TmpForm.Show;
  //Put word doc into print preview mode for a better photo! (see VBA macro help in MS-Word)
  Ole.OleObject.ActiveDocument.ActiveWindow.View.Type = 4; //wdPrintPreview
  //Refresh Ole contents...
  S:= TMemoryStream.create;
  Ole.SaveToStream(S);
  S.Seek(0,soFromBeginning);
  Ole.LoadFromStream(S);
  S.free;
  Application.ProcessMessages;
  //...and wait until OLE has finished loadind (THIS is a crucial point! you HAVE to wait)
  while ShowEstado(false) <> 'Loaded' do
    Application.ProcessMessages;
  //Change Foto size...
  Foto.BitMap.Width:= Ole.Width;
  Foto.BitMap.Height:= Ole.Height;
  //Define rectangle to copy (on canvas)...
  R1.left:= 0;
  R1.top:= 0;
  R1.right:= Foto.Width;
  R1.bottom:= Foto.Height;
  R2.left:= Ole.left+1;
  R2.top:= Ole.top+1;
  R2.right:= Ole.left+Ole.Width-2;
  R2.bottom:= Ole.Top+Ole.Height-2;
  //Take the photo...
  Foto.BitMap.Canvas.CopyRect(R1,TmpForm.Canvas,R2);
  //Hide form (may be you will free it here)
  TmpForm.Visible:= false;
  Ole.modified:= false;

Now you have a bitmap copy of the DOC!

E) If you want to jump page by page and take a picture of each, them you should:

Ole.OleObject.ActiveDocument.Scroll(4); //3=PageUp, 4=PageDown
or
Ole.OleObject.ActiveDocument.ActiveWindow.PageScroll;

Then you can make a photo of the next page of your doc.

For more possible commands to send to Ole.OleObject, open word, goto macro edition, and use the help, most functions can be called using this method, just try them and watch the result on your screen.
0
 
LVL 6

Expert Comment

by:Sergio_Hdez
ID: 9964114
Sorry, I used something in this code I didn't explained:

  while ShowEstado(false) <> 'Loaded' do
    Application.ProcessMessages;

Should be changed to:

while (Ole.State <> osLoaded) do
    Application.ProcessMessages;

Sorry!
0
 
LVL 6

Expert Comment

by:Sergio_Hdez
ID: 13091210
kretzschmar, may be the error comes from the fact that you are free to open ANY document, while this code assumes you have opened a Word doc, so if you opened a bitmap or other type of doc, then the ole server used to open it -word in the expected type of doc- may not know what to do with the command where your error raised.

For instance, having OpenOffice instaled may lead to opening the doc in this program instead of Word, and OpenOffice will not know what to do with Ole.OleObject.ActiveDocument.ActiveWindow.View.Type = 4; as ActiveDocument may not be in its exported interface -sure it is not-.

Anyway, may be I misswrote something, but my original code I didn to try the solution worked ok. May be an older version of word don't understand tis command... I got this command by recording a macro in word in witch I changed view to preview mode, then looke at the code generated, and the constant used resulted to be 4, so I changed it to 4 in the delphi code.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to convert wav to mp3 in delphi 9 169
Virtualstringtree carsh after invalidate for while 5 86
FMX enumerated colours 2 84
Graphics32 under Delphi 10.1 Berlin 2 36
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

911 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now