C#/VB.NET 将PPT或PPTX转换为图像

由于大多数便携式设备支持浏览图片而不支持浏览PowerPoint 文件,所以相比较而言,图像对于用户而言更加友好。除此之外,将PowerPoint文档转换为图像也可以防止对内容做出修改。在本文中,我将展示如何使用 Spire.Presentation for .NET 在C#/VB.NET程序中,将PowerPoint(PPT 和 PPTX)转换为 PNG 或 SVG。

将PPT或PPTX转换为PNG

将PPT或PPTX转换为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

最新文章

  1. sql筛选查询A表中B表已经存在的数据
  2. 大规模web 服务开发技术
  3. 动态规划(DP)
  4. SQL Pass北京举办1周年活动(本次活动特别邀请到了来自微软的SQL Server大师何雷谈数据库职业规划)
  5. Interlocked系列函数线程同步的缺陷
  6. PHP中interface与 implements 关键字
  7. 使用虚拟机win7系统遇到问题及解决
  8. 转: EclipseIDE开发 for C++
  9. vb 修改数据库
  10. POJ1258Agri-Net
  11. Android 开发实践 ViewGroup 实现左右滑出窗口(一)
  12. js--小结⑦---格式转换
  13. C++ Primer笔记4_静态成员类_IO库
  14. 前端构建利器Grunt—Bower
  15. SQLite:自学笔记(1)——快速入门
  16. 【Qt编程】Qt学习笔记&lt;三&gt;
  17. BFS 模拟队列(水题)
  18. 22 , CSS 构造颜色、背景与图像
  19. linux(centos6.9)安装步骤
  20. 解决C#项目出现“此项目引用这台计算机上缺少的 NuGet 程序包。使用 NuGet 程序包还原可下载这些程序包。有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 ..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props”

热门文章

  1. 为什么 Redis 要有哨兵机制?
  2. 使用acme.sh自动申请、续期、部署免费的SSL证书
  3. django框架7
  4. GDOI 2021 普及组溺水记
  5. Linux/Ubuntu 安装Redis
  6. 微信access_token缓存与更新
  7. JS:eval
  8. Mac安装Brew包管理系统
  9. 关于升级最新版本node.js你知道多少?
  10. React技巧之字符串插值