//// <summary>///convert ppt files to PDF files 2/// </summary>/// <param name= "SourcePath" >file path and file name that need to be converted</param>/// <param name= "TargetPath" >path and filename name of the file after conversion is complete</param>/// <returns>Success Returns True, Failure returns false</returns> Public Static BOOLPptconverttopdf (stringSourcePath,stringTargetPath) { BOOLresult; Powerpoint.ppsaveasfiletype PpSaveAsFileType= PowerPoint.PpSaveAsFileType.ppSaveAsPDF;//Convert to PDF ObjectMissing =Type.Missing; Microsoft.Office.Interop.PowerPoint.ApplicationClass Application=NULL; Powerpoint.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; } } returnresult;}//String mac = Interaction.inputbox ("Please enter Mac", "Input Mac", "", ",", ",");//// <summary>///Convert a Word file to a PDF file 2/// </summary>/// <param name= "SourcePath" >file path and file name that need to be converted</param>/// <param name= "TargetPath" >path and filename name of the file after conversion is complete</param>/// <returns>Success Returns True, Failure returns false</returns> Public BOOLWordtopdf (ObjectSourcePath,stringTargetPath) { BOOLresult =false; Wdexportformat wdexportformatpdf=wdexportformat.wdexportformatpdf; ObjectMissing =Type.Missing; Microsoft.Office.Interop.Word.ApplicationClass ApplicationClass=NULL; Microsoft.Office.Interop.Word.Document Document=NULL; Try{ApplicationClass=NewMicrosoft.Office.Interop.Word.ApplicationClass (); Document= ApplicationClass.Documents.Open (refSourcePath,refMissingrefMissingrefMissingrefMissingrefMissingrefMissingrefMissingrefMissingrefMissingrefMissingrefMissingrefMissingrefMissingrefMissingrefmissing); if(Document! =NULL) {document. ExportAsFixedFormat (TargetPath, Wdexportformatpdf,false, Wdexportoptimizefor.wdexportoptimizeforprint, Wdexportrange.wdexportalldocument,0,0, Wdexportitem.wdexportdocumentcontent,true,true, Wdexportcreatebookmarks.wdexportcreatewordbookmarks,true,true,false,refmissing); } result=true; } Catch{result=false; } finally { if(Document! =NULL) {document. Close (refMissingrefMissingrefmissing); Document=NULL; } if(ApplicationClass! =NULL) {Applicationclass.quit (refMissingrefMissingrefmissing); ApplicationClass=NULL; } } returnresult;}
/// <summary>///Open PDF File Method/// </summary>/// <param name= "p" ></param>/// <param name= "Infilepath" >file path and filename</param> Public Static voidPriview (System.Web.UI.Page p,stringInfilepath) {P.response.contenttype="application/pdf"; stringFileName = infilepath.substring (Infilepath.lastindexof ('\\') +1); P.response.addheader ("content-disposition","filename="+fileName); P.response.writefile (Infilepath); P.response.end ();}
C # work PowerPoint to PDF