One, add a reference
Using Microsoft.Office.Core;
Using Microsoft.Office.Interop.PowerPoint;
Second, the conversion method
C # codeCopy
///<summary> ///Convert PowerPoint files to PDF files///</summary> ///<param name= "SourcePath" >Source file path</param> ///<param name= "TargetPath" >Destination file path</param> ///<returns>Success returns TRUE, Failure returns false</returns> Public Static boolPptconverttopdf (StringSourcePath,StringTargetPath){boolResult PpSaveAsFileType PpSaveAsFileType=Ppsaveasfiletype.ppsaveaspdf;//Convert to PDF ObjectMissing=Type.Missing; Microsoft.Office.Interop.PowerPoint.ApplicationClass Application= Null; Presentation persentation= Null;Try {Application= NewMicrosoft.Office.Interop.PowerPoint.ApplicationClass (); Persentation=Application. Presentations.Open (SourcePath, Msotristate.msotrue, Msotristate.msofalse, Msotristate.msofalse);If(persentation!=Null){persentation. SaveAs (TargetPath, PpSaveAsFileType, msotristate.msotrue); } result = true ;} catch {result = false ;} finally { if (persentation ! = null ) {persentation. Close (); Persentation = null ;} If (application ! = null ) {application. Quit (); Application = null ;} } return result; /span>
Third, call
Officetopdf.ppttopdf ("d:\\12345. Pptx", "d:\\12345. PDF");
ASP. NET convert PPT document to PDF