Asp.net converts a ppt document to a pdf file. pptpdf
This document describes how to convert a ppt document to a pdf file by using asp.net. Share it with you for your reference. The specific implementation method is as follows:
1. Add reference
Copy codeThe Code is as follows: using Microsoft. Office. Core;
Using Microsoft. Office. Interop. PowerPoint;
Ii. Conversion Method
Copy codeThe Code is as follows: // <summary>
/// Convert a PowerPoint file to a PDF file
/// </Summary>
/// <Param name = "sourcePath"> source file path </param>
/// <Param name = "targetPath"> target file path </param>
/// <Returns> success returns true, failure returns false </returns>
Public static bool PPTConvertToPDF (string sourcePath, string targetPath)
{
Bool result;
PpSaveAsFileType ppSaveAsFileType = PpSaveAsFileType. ppSaveAsPDF; // convert to pdf
Object missing = Type. Missing;
Microsoft. Office. Interop. PowerPoint. ApplicationClass application = null;
Presentation persentation = null;
Try
{
Application = new Microsoft. 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;
}
Iii. Call
Copy codeThe Code is as follows: OfficeToPdf. PPTToPDF ("d :\\ 12345.pptx", "d :\\ 12345.pdf ");
I hope this article will help you design your asp.net program.