[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1407
  • Last Modified:

How can I open a ppt file in Delphi?

Hi,
I need to open a ppt file (Microsoft Power Point file) in a delphi project and save slides as jpg files.


Thanks

0
faustomen
Asked:
faustomen
1 Solution
 
gwalkeriqCommented:
Unless you want to spend a lot of effort decoding the powerpoint format and replicating all of the drawing logic, you probably want to make PowerPoint handle the work.

Been a long time since I did this, so I don't recall the exact details, but at one time I used automation to open a powerpoint show in powerpoint, and then did a save as for each slide in a separate file (.wmf format as I recall). Once in .wmf format, it would be relativeily easy to playback the .wmf using a suitable  bitmap handle, then convert the bitmap to jpeg format.

You can probably do something similar to this.
0
 
lopemCommented:
I don't think is worth the effort to decode ppt format. Best thing to do is to use OLE automation (I think in www.torry.ru you can find some components to make this task easier).

If you just want to open a ppt file from delphi, use winexec to run powerpoint, but I know this is not what you want. Just in case.

Good luck
Manuel Lopez (lopem)
0
 
gwalkeriqCommented:
You don't really need any components, you can just use the OLE interface. For an example see:
http://www.swissdelphicenter.ch/torry/printcode.php?id=1005 
0
Industry Leaders: 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!

 
gwalkeriqCommented:
If you look at the example, above you could modify it slightly to iterate through all slides and then just grab the bitmap contents directly from the powerpoint slide window if that is easier for you. .WMF files are scalable, but you said you wanted JPG format anyway.
0
 
BlackTigerXCommented:
note (obvious for most people maybe) that if you use OLE (automation), PowerPoint would NEED to be installed in the machine where you would run your program for your program to work
0
 
faustomenAuthor Commented:
Hi qwalkeriq,

I tried the example and it worked fine. But now, how can I "grab the bitmap" ?
My question is about JPG files but if WMF files is better please give me the example to do this.
Thanks

 
0
 
gwalkeriqCommented:
Get the Window Handle using FindWindow or FindWindowEx. I think you will find the class name to be "paneClassDC" -- You can use WinSight to verify this. Convert the window handle to a device context bitmap.canvas.handle.

0
 
Eddie ShipmanAll-around developerCommented:
Follow the instructions here to get it up and running:
http://www.djpate.freeserve.co.uk/AutoPpt.htm

then select the objects you want to save as jpeg and call the save method
using ppSaveAsJPG as the FileFormat.

0
 
Eddie ShipmanAll-around developerCommented:

Here's a simple one:

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComObj, ActiveX, PowerPoint_TLB, Office_TLB;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    PowerPoint: _Application;
  end;

var
  Form1: TForm1;

implementation


{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  AppWasRunning: boolean; // tells you if you can close PowerPoint when you've finished
  Unknown: IUnknown;
  Result: HResult;
begin
  AppWasRunning := False;
  Result := GetActiveObject(CLASS_PowerPointApplication, nil, Unknown);
  if (Result = MK_E_UNAVAILABLE) then
  begin
    PowerPoint := CoPowerPointApplication.Create
  end
  else
  begin
    { make sure no other error occurred during GetActiveObject }
    OleCheck(Result);
    OleCheck(Unknown.QueryInterface(_Application, PowerPoint));
    AppWasRunning := True;
  end;
  PowerPoint.Visible := TOleEnum(msoTrue);
  PowerPoint.Presentations.Open('C:\Documents and Settings\Administrator\Templates\powerpnt2.ppt', msoFalse, msoFalse, msoTrue);
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  EmbedFonts: OleVariant;
begin
  EmbedFonts := False;
  PowerPoint.ActivePresentation.SaveAs('c:\PresName', ppSaveAsJPG, EmbedFonts);
  PowerPoint.ActivePresentation.Close;
  PowerPoint.Quit;
  PowerPoint := nil;
end;
0
 
Eddie ShipmanAll-around developerCommented:
No need to switch to different slides, it saves all as jpg in the directory C:\Presname.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now