C#/VB.NET實(shí)現(xiàn)PPT或PPTX轉(zhuǎn)換為圖像功能
由于大多數(shù)便攜式設(shè)備支持瀏覽圖片而不支持瀏覽PowerPoint 文件,所以相比較而言,圖像對(duì)于用戶而言更加友好。除此之外,將PowerPoint文檔轉(zhuǎn)換為圖像也可以防止對(duì)內(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)目中的引用??梢詮?a rel="external nofollow" target="_blank">此鏈接下載 DLL 文件,也可以通過(guò)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();
//加載一個(gè)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()
'加載一個(gè)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();
//加載一個(gè)PowerPoint文檔
presentation.LoadFromFile("模板.pptx");
//將PowerPoint轉(zhuǎn)換為SVG圖像并以字節(jié)形式存儲(chǔ)在列隊(duì)中
Queue<byte[]> svgBytes = presentation.SaveToSVG();
//獲取列隊(duì)中字節(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()
'加載一個(gè)PowerPoint文檔
presentation.LoadFromFile("模板.pptx")
'將PowerPoint轉(zhuǎn)換為SVG圖像并以字節(jié)形式存儲(chǔ)在列隊(duì)中
Dim svgBytes()> As Queue<byte = presentation.SaveToSVG()
'獲取列隊(duì)中字節(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)圖像的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
C#實(shí)現(xiàn)AddRange為數(shù)組添加多個(gè)元素的方法
這篇文章主要介紹了C#實(shí)現(xiàn)AddRange為數(shù)組添加多個(gè)元素的方法,實(shí)例分析了AddRange方法的使用技巧,需要的朋友可以參考下2015-06-06
C#類型轉(zhuǎn)換之顯式和隱式轉(zhuǎn)換詳解
在C#編程中,類型轉(zhuǎn)換是一個(gè)核心概念,它允許我們?cè)诔绦蛑刑幚聿煌愋偷臄?shù)據(jù),類型轉(zhuǎn)換可以分為兩大類:顯式類型轉(zhuǎn)換和隱式類型轉(zhuǎn)換,在這篇博客中,我們將深入探討這兩種類型轉(zhuǎn)換的定義、用法和重要性,需要的朋友可以參考下2024-07-07
基于C#技術(shù)實(shí)現(xiàn)身份證識(shí)別功能
這篇文章主要介紹了基于C#技術(shù)實(shí)現(xiàn)身份證識(shí)別功能的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-07-07
C# WPF如何反射加載Geometry幾何圖形數(shù)據(jù)圖標(biāo)
這篇文章主要介紹了C# WPF如何反射加載Geometry幾何圖形數(shù)據(jù)圖標(biāo),幫助大家更好的理解和學(xué)習(xí)使用c#,感興趣的朋友可以了解下2021-03-03
C#定制Excel界面并實(shí)現(xiàn)與數(shù)據(jù)庫(kù)交互的方法
這篇文章主要介紹了C#定制Excel界面并實(shí)現(xiàn)與數(shù)據(jù)庫(kù)交互的方法的相關(guān)資料,需要的朋友可以參考下2015-11-11
C#判斷當(dāng)前程序是否通過(guò)管理員運(yùn)行的方法
這篇文章主要介紹了C#判斷當(dāng)前程序是否通過(guò)管理員運(yùn)行的方法,可通過(guò)非常簡(jiǎn)單的系統(tǒng)函數(shù)調(diào)用實(shí)現(xiàn)對(duì)當(dāng)前程序是否通過(guò)管理員運(yùn)行進(jìn)行判定,是非常實(shí)用的技巧,需要的朋友可以參考下2014-11-11

