C# 将PowerPoint文件转换成PDF文件
生活随笔
收集整理的這篇文章主要介紹了
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文檔截圖:
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");
????????}
????}
}
有這方面需要的朋友,可以從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");
????????}
????}
}
總結
以上是生活随笔為你收集整理的C# 将PowerPoint文件转换成PDF文件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 哪些汽车是国六b标准的?
- 下一篇: 隆鑫ke500发动机冷车启动异响?