C # work PowerPoint to PDF

Source: Internet
Author: User

//// <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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.