Solved

Convert MS-Word Doc Into Image

Posted on 2003-11-30
10
906 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

729 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