C# 將PowerPoint文件轉換成PDF文件

PowerPoint的優點在於對演示文檔的操做上,而用PPT查看資料,反而會很麻煩。這時候,把PPT轉換成PDF格式保存,再瀏覽,不失爲一個好辦法。在平常編程中和開發軟件時,咱們也有這樣的須要。本文旨在介紹使用免費的Spire.Presentation庫,使用C#在.NET平臺上實現PowerPoint (.ppt; .pptx)文件到PDF格式文件的轉換。

有這方面須要的朋友,能夠從 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後效果截圖:html

 

 

所有代碼:編程

複製代碼
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");

        }
    }
}
複製代碼
相關文章
相關標籤/搜索