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

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

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
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

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

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
Eddie ShipmanAll-around developerCommented:
No need to switch to different slides, it saves all as jpg in the directory C:\Presname.
0
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
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.