Solved

Convert MS-Word Doc Into Image

Posted on 2003-11-30
10
889 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
Comment Utility
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
Comment Utility
why don't you convert it to pdf & then to bmp !
0
 
LVL 7

Expert Comment

by:sftweng
Comment Utility
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:Aziz_xxx_Habbib
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 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

10 Experts available now in Live!

Get 1:1 Help Now