Navigation Menu Search PhysiologyWeb
PhysiologyWeb Logo Search PhysiologyWeb
   
— share —
Share on Facebook    Share on X    Share on LinkedIn    Share on Pinterest    Share on Reddit    Email    Copy URL
procedure TForm1.SaveMicrosoftPowerPointFileAsPDFFile(Sender: TObject);
var
PowerPointFileName, PDFFileName: String;
PowerPointApplication, PowerPointPresentation: Variant;
begin
//be sure ComObj and Variants units are included in the "uses" clause

PowerPointFileName := 'C:\PhysiologyWeb\delphi_code_examples\powerpoint_file.pptx'; //replace file name with the name of your file
PDFFileName := ChangeFileExt(PowerPointFileName, '.pdf');

PowerPointApplication := Null;
PowerPointPresentation := Null;

try
//create PowerPoint OLE
PowerPointApplication := CreateOleObject('PowerPoint.Application');
except
PowerPointApplication := Null;
//add error/exception handling code as desired
end;

If VarIsNull(PowerPointApplication) = False then
begin
try
PowerPointApplication.Visible := True; //set to False if you do not want to see the activity in the background
PowerPointApplication.DisplayAlerts := False; //ensures message dialogs do not interrupt the flow of your automation process. May be helpful to set to True during testing and debugging.

//Open PowerPoint Presentation
try
PowerPointPresentation := PowerPointApplication.Presentations.Open(PowerPointFileName);
//reference
//https://docs.microsoft.com/en-us/office/vba/api/powerpoint.presentations.open
except
PowerPointPresentation := Null;
//add error/exception handling code as desired
end;

If VarIsNull(PowerPointPresentation) = False then
begin
PowerPointPresentation.SaveAs(PDFFileName, 32); //ppSaveAsPDF = 32
//or
//PowerPointApplication.ActivePresentation.SaveAs(PDFFileName, 32);
//If a pdf file with the same name already exists, it overwrites it. Write additional code to address as desired.
//parameters:
//Name Required/Optional Data type Description
//FileName Required String Specifies the name to save the file under. If you don't include a full path, PowerPoint saves the file in the current folder.
//FileFormat Optional PpSaveAsFileType Specifies the saved file format. If this argument is omitted, the file is saved in the default file format (ppSaveAsDefault).
//EmbedFonts Optional MsoTriState Specifies whether PowerPoint embeds TrueType fonts in the saved presentation.
//see references below for additional optional parameters
//references
//https://docs.microsoft.com/en-us/office/vba/api/powerpoint.presentation.saveas
//https://docs.microsoft.com/en-us/office/vba/api/powerpoint.ppsaveasfiletype
end;
finally
PowerPointPresentation.Close;
PowerPointApplication.DisplayAlerts := True;
PowerPointApplication.Quit;

PowerPointPresentation := Unassigned;
PowerPointApplication := Unassigned;
end;
end;
end;




Posted: Sunday, September 4, 2022
Last updated: Tuesday, March 18, 2025
— share —
Share on Facebook    Share on X    Share on LinkedIn    Share on Pinterest    Share on Reddit    Email    Copy URL