Convert MS-Word Doc Into Image

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

           to convert using OLE
           any else method)

Please Help me!!!!

Thank you very much

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.

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)?

why don't you convert it to pdf & then to bmp !
OWASP Proactive Controls

Learn the most important control and control categories that every architect and developer should include in their projects.

Aziz_xxx_HabbibAuthor Commented:
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


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;
  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):


or from a file:


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;
  //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;
  //...and wait until OLE has finished loadind (THIS is a crucial point! you HAVE to wait)
  while ShowEstado(false) <> 'Loaded' do
  //Change Foto size...
  Foto.BitMap.Width:= Ole.Width;
  Foto.BitMap.Height:= Ole.Height;
  //Define rectangle to copy (on canvas)...
  R1.left:= 0; 0;
  R1.right:= Foto.Width;
  R1.bottom:= Foto.Height;
  R2.left:= Ole.left+1;;
  R2.right:= Ole.left+Ole.Width-2;
  R2.bottom:= Ole.Top+Ole.Height-2;
  //Take the photo...
  //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

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.

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
Sorry, I used something in this code I didn't explained:

  while ShowEstado(false) <> 'Loaded' do

Should be changed to:

while (Ole.State <> osLoaded) do

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.
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

From novice to tech pro — start learning today.