This article illustrates the asp.net implementation of the method of translating a PPT document into PDF. Share to everyone for your reference. The implementation methods are as follows:
One, add a reference
Copy Code code as follows:
Using Microsoft.Office.Core;
Using Microsoft.Office.Interop.PowerPoint;
Second, the conversion method
Copy Code code as follows:
<summary>
Convert PowerPoint files to PDF format files
</summary>
<param name= "SourcePath" > source file path </param>
<param name= "TargetPath" > Destination file path </param>
<returns> returns true successfully, Failure returns false</returns>
public static bool Pptconverttopdf (string SourcePath, String TargetPath)
{
BOOL result;
PpSaveAsFileType PpSaveAsFileType = ppsaveasfiletype.ppsaveaspdf;//converted 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;
}
Third, call
Copy Code code as follows:
Officetopdf.ppttopdf ("D:\\12345.pptx", "d:\\12345.pdf");
I hope this article will help you with the ASP.net program design.