PowerPoint的優勢在於對演示文檔的操作上,而用PPT查看資料,反而會很麻煩。這時候,把PPT轉換成PDF格式保存,再瀏覽,不失為一個好辦法。在日常編程中和開發軟件時,我們也有這樣的需要。本文旨在介紹使用免費的Spire.Presentation庫,使用C#在.NET平台上實現PowerPoint (.ppt; .pptx)文件到PDF格式文件的轉換。
有這方面需要的朋友,可以從 E-iceblue官方下載使用。下載完成后,請將bin文件夾的.DLL添加作為Visual Studio的引用。免費版本只能轉3頁。代碼示例如下:
步驟1:創建新的presentation對象。
有這方面需要的朋友,可以從 E-iceblue官方下載使用。下載完成后,請將bin文件夾的.DLL添加作為Visual Studio的引用。免費版本只能轉3頁。代碼示例如下:
步驟1:創建新的presentation對象。
Presentation presentation = new Presentation()
步驟2:加載PPT文檔。
presentation.LoadFromFile("Sample.pptx");
步驟3:將PPT文檔轉換為PDF文檔。
presentation.SaveToFile("ToPdf.pdf", FileFormat.PDF);
步驟4:啟動文檔查看效果。
System.Diagnostics.Process.Start("ToPdf.pdf");
原PPT文檔截圖:

轉換成PDF后效果截圖:

全部代碼:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spire.Presentation;
namespace PPT轉PDF
{
class Program
{
static void Main(string[] args)
{
Presentation presentation = new Presentation();
presentation.LoadFromFile("Sample.pptx");
presentation.SaveToFile("ToPdf.pdf", FileFormat.PDF);
System.Diagnostics.Process.Start("ToPdf.pdf");
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spire.Presentation;
namespace PPT轉PDF
{
class Program
{
static void Main(string[] args)
{
Presentation presentation = new Presentation();
presentation.LoadFromFile("Sample.pptx");
presentation.SaveToFile("ToPdf.pdf", FileFormat.PDF);
System.Diagnostics.Process.Start("ToPdf.pdf");
}
}
}

