当前位置:网站首页>C#/VB.NET 将PPT或PPTX转换为图像
C#/VB.NET 将PPT或PPTX转换为图像
2022-08-01 10:52:00 【InfoQ】
C#/VB.NET 将PPT或PPTX转换为图像
由于大多数便携式设备支持浏览图片而不支持浏览PowerPoint 文件,所以相比较而言,图像对于用户而言更加友好。除此之外,将PowerPoint文档转换为图像也可以防止对内容做出修改。在本文中,我将展示如何使用
Spire.Presentation for .NET
在C#/VB.NET程序中,将PowerPoint(PPT 和 PPTX)转换为 PNG 或 SVG。
l
将PPT或PPTX转换为PNG
l
将PPT或PPTX转换为SVG
安装 Spire.Presentation for .NET
首先,我们需要将
Spire.Presentation for .NET
包中包含的 DLL 文件添加为 .NET 项目中的引用。可以从
此链接
下载 DLL 文件,也可以通过
NuGet
安装 DLL 文件。
PM> Install-Package Spire.Presentation
将PPT或PPTX转换为PNG
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);
}
}
}
}
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
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();
}
}
}
}
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


边栏推荐
- MFC实现交通图导航系统
- DBPack SQL Tracing 功能及数据加密功能详解
- IntellJ IDEA如何显示换行符(line endings)
- Solve vscode input! Unable to quickly generate skeletons (three methods for the new version of vscode to quickly generate skeletons)
- CTO strongly banning the use of the Calendar, that in what?
- .NET深入解析LINQ框架(三:LINQ优雅的前奏)
- Mysql索引相关的知识复盘一
- STM32 Personal Notes - Watchdog
- 一篇文章,带你详细了解华为认证体系证书(1)
- activiti工作流的分页查询避坑
猜你喜欢
随机推荐
千万级乘客排队系统重构&压测方案——总结篇
Mysql索引相关的知识复盘一
Qt supports HEIC/HEIF format images
Google Earth Engine——给影像添加一个属性对于单景的时间序列并返回影像
MTK6225-紧急电话
【cartographer ros】十: 延时和误差分析
将本地项目推送到远程仓库
CTO strongly banning the use of the Calendar, that in what?
For small applications, which database is better to use?
WTM:ASP.NET Core快速开发利器!
How to find out hidden computer software (how to clean up the computer software hidden)
2022年7月31日--使用C#迈出第一步--使用C#中的数组和foreach语句来存储和循环访问数据序列
阿里腾讯面试一二
报告:想学AI的学生数量已涨200%,老师都不够用了
小程序毕设作品之微信美食菜谱小程序毕业设计成品(3)后台功能
小程序毕设作品之微信美食菜谱小程序毕业设计成品(2)小程序功能
进制与转换、关键字
STM32入门开发 介绍IIC总线、读写AT24C02(EEPROM)(采用模拟时序)
Golang内存分析工具gctrace和pprof实战
4种常见的鉴权方式及说明