網站首頁 編程語言 正文
由于大多數便攜式設備支持瀏覽圖片而不支持瀏覽PowerPoint 文件,所以相比較而言,圖像對于用戶而言更加友好。除此之外,將PowerPoint文檔轉換為圖像也可以防止對內容做出修改。在本文中,我將展示如何使用?Spire.Presentation for .NET?在C#/VB.NET程序中,將PowerPoint(PPT 和 PPTX)轉換為 PNG 或 SVG。
安裝 Spire.Presentation for .NET
首先,我們需要將?Spire.Presentation for .NET 包中包含的 DLL 文件添加為 .NET 項目中的引用。可以從此鏈接下載 DLL 文件,也可以通過NuGet?安裝 DLL 文件。
PM> Install-Package Spire.Presentation
將PPT或PPTX轉換為PNG
C#
using Spire.Presentation;
using System;
using System.Drawing;
using System.Drawing.Imaging;
namespace ConvertPowerPointToPng
{
class Program
{
static void Main(string[] args)
{
//初始化Presentation實例
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實例
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轉換為SVG
C#
using System.Collections.Generic;
using System.IO;
namespace PPTtoSVG
{
class Program
{
static void Main(string[] args)
{
//初始化Presentation實例
Presentation presentation = new Presentation();
//加載一個PowerPoint文檔
presentation.LoadFromFile("模板.pptx");
//將PowerPoint轉換為SVG圖像并以字節形式存儲在列隊中
Queue<byte[]> svgBytes = presentation.SaveToSVG();
//獲取列隊中字節數組生成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實例
Dim presentation As Presentation = New Presentation()
'加載一個PowerPoint文檔
presentation.LoadFromFile("模板.pptx")
'將PowerPoint轉換為SVG圖像并以字節形式存儲在列隊中
Dim svgBytes()> As Queue<byte = presentation.SaveToSVG()
'獲取列隊中字節數組生成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
相關推薦
- 2022-09-29 Python組合數據類型詳解_python
- 2022-07-28 Redis基本數據類型Set常用操作命令_Redis
- 2022-12-10 OpenMP深入剖析reduction子句教程_C 語言
- 2022-08-01 Python+Selenium鍵盤鼠標模擬事件操作詳解_python
- 2022-06-24 C#利用itext實現PDF頁面處理與切分_C#教程
- 2023-04-14 使用?React?hooks?實現類所有生命周期_React
- 2022-04-04 微信小程序:返回上一頁,刷新頁面內容
- 2022-07-10 $route和this.$router區別
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支