C#/VB.NET實(shí)現(xiàn)PPT或PPTX轉(zhuǎn)換為圖像功能
由于大多數(shù)便攜式設(shè)備支持瀏覽圖片而不支持瀏覽PowerPoint 文件,所以相比較而言,圖像對于用戶而言更加友好。除此之外,將PowerPoint文檔轉(zhuǎn)換為圖像也可以防止對內(nèi)容做出修改。在本文中,我將展示如何使用 Spire.Presentation for .NET 在C#/VB.NET程序中,將PowerPoint(PPT 和 PPTX)轉(zhuǎn)換為 PNG 或 SVG。
安裝 Spire.Presentation for .NET
首先,我們需要將 Spire.Presentation for .NET 包中包含的 DLL 文件添加為 .NET 項(xiàng)目中的引用。可以從此鏈接下載 DLL 文件,也可以通過NuGet 安裝 DLL 文件。
PM> Install-Package Spire.Presentation
將PPT或PPTX轉(zhuǎn)換為PNG
C#
using Spire.Presentation; using System; using System.Drawing; using System.Drawing.Imaging; namespace ConvertPowerPointToPng { class Program { static void Main(string[] args) { //初始化Presentation實(shí)例 Presentation presentation = new Presentation(); //加載一個PowerPoint文檔 presentation.LoadFromFile("模板.pptx"); //遍歷PowerPoint文檔中的幻燈片并保存為PNG圖片 for (int i = 0; i < presentation.Slides.Count; i++) { Image image = presentation.Slides[i].SaveAsImage(); String fileName = String.Format("圖片{0}.png", i); image.Save(fileName, System.Drawing.Imaging.ImageFormat.Png); } } } }
VB.NET
Imports Spire.Presentation Imports System Imports System.Drawing Imports System.Drawing.Imaging Namespace ConvertPowerPointToPng Class Program Shared Sub Main(ByVal args() As String) '初始化Presentation實(shí)例 Dim presentation As Presentation = New Presentation() '加載一個PowerPoint文檔 presentation.LoadFromFile("模板.pptx") '遍歷PowerPoint文檔中的幻燈片并保存為PNG圖片 Dim i As Integer For i = 0 To presentation.Slides.Count- 1 Step i + 1 Dim image As Image = presentation.Slides(i).SaveAsImage() Dim fileName As String = String.Format("圖片{0}.png",i) image.Save(fileName, System.Drawing.Imaging.ImageFormat.Png) Next End Sub End Class End Namespace
效果圖
將PPT或PPTX轉(zhuǎn)換為SVG
C#
using System.Collections.Generic; using System.IO; namespace PPTtoSVG { class Program { static void Main(string[] args) { //初始化Presentation實(shí)例 Presentation presentation = new Presentation(); //加載一個PowerPoint文檔 presentation.LoadFromFile("模板.pptx"); //將PowerPoint轉(zhuǎn)換為SVG圖像并以字節(jié)形式存儲在列隊中 Queue<byte[]> svgBytes = presentation.SaveToSVG(); //獲取列隊中字節(jié)數(shù)組生成SVG文件 int len = svgBytes.Count; for (int i = 0; i < len; i++) { FileStream fs = new FileStream(string.Format("圖片-{0}.svg", i), FileMode.Create); byte[] bytes = svgBytes.Dequeue(); fs.Write(bytes, 0, bytes.Length); presentation.Dispose(); } } } }
VB.NET
Imports System.Collections.Generic Imports System.IO Namespace PPTtoSVG Class Program Shared Sub Main(ByVal args() As String) '初始化Presentation實(shí)例 Dim presentation As Presentation = New Presentation() '加載一個PowerPoint文檔 presentation.LoadFromFile("模板.pptx") '將PowerPoint轉(zhuǎn)換為SVG圖像并以字節(jié)形式存儲在列隊中 Dim svgBytes()> As Queue<byte = presentation.SaveToSVG() '獲取列隊中字節(jié)數(shù)組生成SVG文件 Dim len As Integer = svgBytes.Count Dim i As Integer For i = 0 To len- 1 Step i + 1 Dim fs As FileStream = New FileStream(String.Format("圖片-{0}.svg",i),FileMode.Create) Dim bytes() As Byte = svgBytes.Dequeue() fs.Write(bytes, 0, bytes.Length) presentation.Dispose() Next End Sub End Class End Namespace
效果圖
以上就是C#/VB.NET實(shí)現(xiàn)PPT或PPTX轉(zhuǎn)換為圖像功能的詳細(xì)內(nèi)容,更多關(guān)于C# PPT轉(zhuǎn)圖像的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
c#中(int)、int.Parse()、int.TryParse、Convert.ToInt32的區(qū)別詳解
這篇文章主要介紹了c#中(int)、int.Parse()、int.TryParse、Convert.ToInt32的區(qū)別,需要的朋友可以參考下2014-07-07C#中判斷某類型是否可以進(jìn)行隱式類型轉(zhuǎn)換
在我們采用反射動態(tài)調(diào)用一些方法時,常常涉及到類型的轉(zhuǎn)換,直接判斷類型是否相符有時不能判斷調(diào)用方法是否合適2013-04-04Unity3D舊電視濾鏡shader的實(shí)現(xiàn)示例
這篇文章主要介紹了Unity3D舊電視濾鏡shader的實(shí)現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-04-04