Solved

Convert MS-Word Doc Into Image

Posted on 2003-11-30
10
901 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
Technology Partners: 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

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!

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

749 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