Solved

convert word doc to image/picture format

Posted on 2002-06-28
8
775 Views
Last Modified: 2010-04-04
hi all,

  does anyone knows how to convert a word document into an image format (i.e. bmp/jpg/gif) using delphi? please post working codes if you know how. thanks!

i'll increase the points when necessary.
0
Comment
Question by:third
8 Comments
 
LVL 3

Expert Comment

by:lopem
ID: 7116667
listening...
0
 
LVL 3

Expert Comment

by:lopem
ID: 7117440
Hi Third,

I was thinking in your problem and I found these results:

I dont think its possible to copy to Delphi every picture in a Word document automatically. The problem is the way Word Basic (the last instance command language for MsWord), handles a cut/copy of a picture on a document. Word assigns a name "picture 2", "picture 9" in some random way that I cant figure out how it works. I didnt find the proper generic automated function to use it with OLE.

Nevertheless, if you have lots of pictures in a Word document and want them in BMP format, for example, try this code (tested in Delphi 5):

Put an Image object, a save dialog, and a button.

Then try:

procedure TForm1.Button1Click(Sender: TObject);
begin
 if Clipboard.HasFormat(CF_Picture) then     { is there a bitmap on the Clipboard? }
 begin
   Image1.Picture.Assign(Clipboard);
 end;
  SaveDialog1.Execute;
  if SaveDialog1.FileName <> '' then
   Image1.Picture.SaveToFile(SaveDialog1.FileName);
end;


So I used the next procedure: I executed MsWord and load a document with images. Then, I clicked on right mouse button over an image and cut/copy the image selected in document. Changed the focus to my delphi application and clicked the button to load the image and save it as a bmp file.

Hope this helps.
best regards,
Manuel Lopez (lopem)
0
 
LVL 3

Expert Comment

by:lopem
ID: 7117455
Third,

Sorry, I forgot few more details... First, use the clipbrd unit in your uses clauses and second, I didnt read your question carefully. You want to make a document an image, right? well  the only way I can think to do that is to click on MsWord preview and copy the content of the display to the clipboard. This way you can make every page of a document a bmp file using the code presented in my last message.

(A better solution is to use Adobe Acrobat Distiller to create a PDF file of the document).

best wishes
Manuel Lopez (lopem)
0
 
LVL 30

Author Comment

by:third
ID: 7121037

hi, could you show me working codes on how to convert a word doc to pdf? also, kindly specify what components i need to import to produce one. thanks...
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.

 
LVL 3

Accepted Solution

by:
lopem earned 150 total points
ID: 7122426
Converting a document to PDF is not an easy task. You need at least a component or Adobe Distiller to do that. Distiller software is expensive (I guess around 500 dlls)...  Anyway, I dont think you can find any free component to such that task but take a look to these sites:

http://www.synactis.com/products/pdf_delphi.htm

 
                 Nishita's PDF Creation VCL v.2.0  
                 PowerPdf v.0.9 beta  
                 PasPDF v.0.943  

at    http://www.torry.net/index.htm

or a commercial one: http://www.wptools.de/html/wpdf.htm

best regards.
Manuel Lopez (lopem)
0
 
LVL 1

Expert Comment

by:MBo
ID: 7123710
I used RXRichEdit from RXLib because it can show pictures.
Save Word document as RTF.

uses ...richedit;

procedure TForm1.Button1Click(Sender: TObject);
var b:tbitmap;
  fr: TFormatRange;
  r: TRect;
begin
rxrichedit1.Lines.LoadFromFile('e:\wwe.rtf');
b:=tbitmap.create;
b.width:=rxrichedit1.width;
b.height:=rxrichedit1.height;
r:=rect(0,0,RXRichEdit1.Width*screen.Pixelsperinch,
                    RXRichEdit1.Height*screen.Pixelsperinch);
fr.hdc:=b.Canvas.handle;
fr.hdctarget:=b.Canvas.handle;
fr.rc:=r;
fr.rcpage:=r;
fr.chrg.cpMin:=0;
fr.chrg.cpMax:=-1;
Sendmessage(RXRichEdit1.handle,EM_FORMATRANGE,1,longint(@fr));
image1.Picture.assign(b);//just to control
b.savetofile('e:\wwe.bmp');
b.free;
end;
0
 
LVL 30

Author Comment

by:third
ID: 7139680
MBo,

the document need not support pictures (only formatted texts) in the document so i just used richedit on my testing. your code works but it only save what is currently visible in the richedit component. is it possible to do a per page saving?
0
 

Expert Comment

by:hrabih75
ID: 7540706
To produce a pdf file, you can get the PDF Converter from www.amyuni.com that can do the job without even using components
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

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

937 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

11 Experts available now in Live!

Get 1:1 Help Now