C#学习笔记(23)——C#将PPT批量转为JPG(aspose方法)
说明(2017-7-31 18:30:25):
1. 最主要的是下载到aspose的破解文件,我在这里下载的http://www.lenosoft.net/down/10205.htm,如果不差钱可以买正版,也就一万多。有试用版,不过转换完有水印,水印很大,很大。
2. aspose没有给出直接将PPT转为图片的方法,只能是先将PPT转为PDF,再将PDF转为图片。所以只用到了两个dll文件,Aspose.Slides和Aspose.Pdf。
3. 其实有个网站上有教程,是aspose的中国代理,里面的英文视频教学免费,但中文的收费,还有一些文档是免费的,还是比较厚道的。http://training.evget.com/video/5975
4. 但是总感觉这种方法还是麻烦,虽然aspose号称最大的优势是不用安装office也能操作,但是你既然要做这个功能电脑不装office不是有病?觉得微软应该有一套自己的解决方案,再研究研究,毕竟两个dll拖家带口的也好几十兆,一堆方法用起来也是累。
5. 网上找资料的时候,博客里基本上都是那一篇公司项目里的部分代码,最关键的部分居然封装到他们自己的类里面了,而且没有贴上这个类的代码,这你让我们用个鬼!
6. 我发现自己做一个功能的时候,看到网上博客里长篇大论,总感觉不至于这么难吧?应该很少代码就能实现了,然后就自己写,果然少写不少,难道是我太聪明了?又或许是我代码不够严谨?去他娘的,能用就行!出了事再找问题。
xaml:
<Window x:Class="PPTtoJPG.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="" Width="">
<Grid>
<Button Content="打开" HorizontalAlignment="Left" Height="" Margin="370,64,0,0" VerticalAlignment="Top" Width="" Click="Button_Click"/>
<Button Content="开始转成PDF" HorizontalAlignment="Left" Height="" Margin="48,205,0,0" VerticalAlignment="Top" Width="" Click="Button_Click_1"/>
<Label Content="PPT路径" HorizontalAlignment="Left" Height="" Margin="34,64,0,0" VerticalAlignment="Top" Width=""/>
<TextBox Name="txtBoxPath" HorizontalAlignment="Left" Height="" Margin="129,66,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width=""/>
<Button Content="开始转成图片" HorizontalAlignment="Left" Height="" Margin="307,205,0,0" VerticalAlignment="Top" Width="" Click="Button_Click_2"/> </Grid>
</Window>
代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;
using Aspose.Slides;
using System.Reflection;
using Aspose.Pdf;
using System.Drawing.Imaging;
using System.Drawing;
using Aspose.Pdf.Devices; namespace PPTtoJPG
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
File.Delete("log.txt"); }
private void ShowLog(string log)
{
File.AppendAllText("log.txt", "\r\n" + DateTime.Now.ToString() + ": " + log);
}
private void Button_Click(object sender, RoutedEventArgs e)
{ }
//PPT转成PDF
private void Button_Click_1(object sender, RoutedEventArgs e)
{ //Crack();
string pptPath = txtBoxPath.Text;
if (pptPath != "" && Directory.Exists(pptPath))
{
DirectoryInfo pptInfos = new DirectoryInfo(pptPath); foreach (FileInfo pptInfo in pptInfos.GetFiles("*.ppt*"))
{
//如果已经存在这个pdf就跳过
if (File.Exists(pptInfo.FullName.Split('.')[] + ".pdf"))
{
continue;
}
try
{
Presentation pres = new Presentation(pptInfo.FullName); pres.Save(pptInfo.FullName.Split('.')[] + ".pdf", Aspose.Slides.Export.SaveFormat.Pdf); Console.WriteLine(pptInfo.FullName.Split('.')[] + ".pdf");
}
catch (Exception)
{ //throw;
Console.WriteLine("无法生成" + pptInfo.FullName.Split('.')[] + ".pdf");
ShowLog("无法生成" + pptInfo.FullName.Split('.')[] + ".pdf");
//MessageBox.Show("无法生成" + pptInfo.FullName.Split('.')[0] + ".pdf");
continue;
} }
MessageBox.Show("转换pdf完成!");
}
else
{
MessageBox.Show("路径为空或不存在!");
}
} //PDF转成JPG
private void Button_Click_2(object sender, RoutedEventArgs e)
{
string pdfPath = txtBoxPath.Text;
if (pdfPath != "" && Directory.Exists(pdfPath))
{
DirectoryInfo pdfInfos = new DirectoryInfo(pdfPath); foreach (FileInfo pdfInfo in pdfInfos.GetFiles("*.pdf"))
{ Directory.CreateDirectory(pdfInfo.FullName.Split('.')[]);
//open document
Document pdfDoc = new Document(pdfInfo.FullName);
for (int i = ; i < pdfDoc.Pages.Count; i++)
{
string imgPath = pdfInfo.FullName.Split('.')[] + @"\" + (i + ).ToString() + ".jpg";
using (FileStream imageStream = new FileStream(imgPath, FileMode.Create))
{
//Width, Height, Resolution, Quality
//Quality [0-100], 100 is Maximum
//create Resolution object
//300是分辨率
Resolution resolution = new Resolution();
//默认是3000x2250尺寸,100是画质最高
JpegDevice jpegDevice = new JpegDevice(, , resolution, );
//convert a particular page and save the image to stream
jpegDevice.Process(pdfDoc.Pages[i + ], imageStream);
//close stream
imageStream.Close();
}
}
}
MessageBox.Show("转换图片完成!");
}
else
{
MessageBox.Show("路径为空或不存在!");
}
}
}
}
C#学习笔记(23)——C#将PPT批量转为JPG(aspose方法)的更多相关文章
- Ext.Net学习笔记23:Ext.Net TabPanel用法详解
Ext.Net学习笔记23:Ext.Net TabPanel用法详解 上面的图片中给出了TabPanel的一个效果图,我们来看一下代码: <ext:TabPanel runat="se ...
- C#数字图像处理算法学习笔记(一)--C#图像处理的3中方法
C#数字图像处理算法学习笔记(一)--C#图像处理的3中方法 Bitmap类:此类封装了GDI+中的一个位图,次位图有图形图像及其属性的像素数据组成.因此此类是用于处理像素数据定义的图形的对象.该类的 ...
- [原创]java WEB学习笔记23:MVC案例完整实践(part 4)---模糊查询的设计与实现
本博客为原创:综合 尚硅谷(http://www.atguigu.com)的系统教程(深表感谢)和 网络上的现有资源(博客,文档,图书等),资源的出处我会标明 本博客的目的:①总结自己的学习过程,相当 ...
- JNI学习笔记_Java调用C —— 非Android中使用的方法
一.学习笔记 1.java源码中的JNI函数本机方法声明必须使用native修饰. 2.相对反编译 Java 的 class 字节码文件来说,反汇编.so动态库来分析程序的逻辑要复杂得多,为了应用的安 ...
- Dynamic CRM 2013学习笔记(十七)JS读写各种类型字段方法及技巧
我们经常要对表单里各种类型的字段进行读取或赋值,下面列出各种类型的读写方法及注意事项: 1. lookup 类型 清空值 var state = Xrm.Page.getAttribute(" ...
- Dynamic CRM 2013学习笔记(二十七)无代码 复制/克隆方法
前面介绍过二种复制/克隆方法:<Dynamic CRM 2013学习笔记(十四)复制/克隆记录> 和<Dynamic CRM 2013学习笔记(二十五)JS调用web service ...
- C#学习笔记(24)——C#将PPT批量转为JPG(最简单的方法)
说明(2017-8-1 11:15:46): 1. 哈哈,我就说微软肯定有自己的办法,把PPT转成图片. 2. 主要是要引入两个微软自己的程序集,vs里自带直接添加引用,注意一下版本,12.0是off ...
- Linux下汇编语言学习笔记23 ---
这是17年暑假学习Linux汇编语言的笔记记录,参考书目为清华大学出版社 Jeff Duntemann著 梁晓辉译<汇编语言基于Linux环境>的书,喜欢看原版书的同学可以看<Ass ...
- struts2学习笔记--上传单个和批量文件示例
struts2提供了对上传文件的支持,将上传后的文件封装为java.io.File对象,开发者只需要在Action中定义一个File类型的变量,然后直接使用该变量,将它复制到目的目录即可. 单个文件上 ...
随机推荐
- HDU Bomb Game 3622 (2-Sat)
Bomb Game Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- iOS 限制输入字数完美解决方案
关于限制输入字数以前也做过,网上也很多方法.但都不够完美,本方法可防止中文联想.粘贴等突破长途限制.可防止Emoji截为两半导致编码出问题. - (void)textFieldDidChange: ...
- org.hibernate.exception.ConstraintViolationException: could not insert:
org.hibernate.exception.ConstraintViolationException: could not insert: 报错原由于xxx.hbm.xml文件里的主键类型设置有问 ...
- [转]Redis几个认识误区
转自timyang:http://timyang.net/data/redis-misunderstanding/ 前几天微博发生了一起大的系统故障,很多技术的朋友都比较关心,其中的原因不会超出Jam ...
- CentOS7安装Tomcat
一.二进制包安装Tomcat 1.下载解压二进制包 wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.32/bi ...
- Java 8 – Period and Duration examples
Few examples to show you how to use Java 8 Duration, Period and ChronoUnit objects to find out the d ...
- java中使用for遍历集合是注意的空指针异常
public static void main(String[] args) { List<Object> a = null; for(Object i : a)//会有空指针异常 { } ...
- scrapy定时执行抓取任务
在ubuntu环境下,使用scrapy定时执行抓取任务,由于scrapy本身没有提供定时执行的功能,所以采用了crontab的方式进行定时执行: 首先编写要执行的命令脚本cron.sh #! /bin ...
- yarn 的安装
yarn的安装方法: https://yarn.bootcss.com/docs/install.html#linux-tab
- 携程的配置中心(阿波罗apollo)
https://github.com/ctripcorp/apollo https://pan.baidu.com/s/1dFEGMIX#list/path=%2Fmeetup%20ppt%2F040 ...