網(wǎng)站首頁 編程語言 正文
由于大多數(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)目中的引用。可以從此鏈接下載 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();
//加載一個(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
效果圖
原文鏈接:https://www.cnblogs.com/Gia-/p/16539060.html
相關(guān)推薦
- 2022-11-07 C語言字符串函數(shù)模擬實(shí)現(xiàn)流程介紹_C 語言
- 2022-03-14 sql 排序order by重復(fù)數(shù)據(jù)問題
- 2022-09-12 Go1.18新特性工作區(qū)模糊測試及泛型的使用詳解_Golang
- 2022-06-28 ES6基礎(chǔ)語法之Map和Set對(duì)象_基礎(chǔ)知識(shí)
- 2022-03-29 C語言的基本編寫規(guī)范你了解嗎_C 語言
- 2022-04-23 Python實(shí)現(xiàn)B站UP主小助手詳解開發(fā)流程_python
- 2022-07-10 手動(dòng)實(shí)現(xiàn)function isInstanceOf(child,Parent)
- 2022-12-13 Python使用Matplotlib繪制三維散點(diǎn)圖詳解流程_python
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支