C#pdf 切割成图片
引用
using Ghostscript.NET;
using Ghostscript.NET.Rasterizer;
需要安装 exe文件
public static GhostscriptVersionInfo _lastInstalledVersion = null;
public static GhostscriptRasterizer _rasterizer = null;
PdfToImages(string pdfInputPath, string imageOutputPath)
{
//解析度
int desired_x_dpi = Convert.ToInt32(96);
int desired_y_dpi = Convert.ToInt32(96);
Log.writeLog("生成临时文件夹");
var destFile = GetFilePath(pdfInputPath);
Log.writeLog("复制pdf资料");
System.IO.File.Copy(pdfInputPath, destFile, true);
Log.writeLog("复制pdf资料完成");
if (System.IO.File.Exists(destFile))
{
try
{
_lastInstalledVersion = GhostscriptVersionInfo.GetLastInstalledVersion( GhostscriptLicense.GPL | GhostscriptLicense.AFPL, GhostscriptLicense.GPL);
_rasterizer = new GhostscriptRasterizer();
_rasterizer.Open(destFile, _lastInstalledVersion, false);
for (var i = 1; i <= endPageNum; i++)
{
string pageFilePath = Path.Combine(imageOutputPath, imageName + "_" + i.ToString() + "." + imageFormat.ToString());
Image img = _rasterizer.GetPage(desired_x_dpi, desired_y_dpi, i);
img.Save(pageFilePath, ImageFormat.Jpeg);
}
_rasterizer.Dispose();
}
catch (Exception ex)
{
Log.writeLog("Exception:" + ex.ToString());
System.IO.File.Delete(destFile);
}
finally
{
Log.writeLog("finally:删除资料");
System.IO.File.Delete(destFile);
//System.IO.Direc
}
/// <summary>
/// 根据源文件路径获取新重新命名的文件路径
/// </summary>
/// <param name="filePath"></param>
/// <returns></returns>
static string GetFilePath(string filePath)
{
if (string.IsNullOrWhiteSpace(filePath))
{
return string.Empty;
}
else
{
return string.Format("{0}{1}{2}", filePath.Substring(0, filePath.LastIndexOf('\\') + 1), Guid.NewGuid().ToString("N").Replace("-", ""), filePath.Substring(filePath.LastIndexOf('.')));
}
}
C#pdf 切割成图片的更多相关文章
- C#技术分享【PDF转换成图片——13种方案】(2013-07-25重新整理)
原文:C#技术分享[PDF转换成图片--13种方案](2013-07-25重新整理) 重要说明:本博已迁移到 石佳劼的博客,有疑问请到 文章新地址 留言!!! 写在最前面:为了节约大家时间,撸主把最常 ...
- C#技术分享【PDF转换成图片——11种方案】
1.[iTextSharp.dll],C# 开源PDF处理工具,可以任意操作PDF,并可以提取PDF中的文字和图片,但不能直接将PDF转换成图片. DLL和源码 下载地址:http://downloa ...
- 在linux环境下使用icepdf或pdfbox将pdf转化成图片是乱码解决
在linux环境下使用icepdf或pdfbox将pdf转化成图片是出现乱码,网上查发下是itextpdf生成pdf引用"STSong-Light"字体而linux环境下没有这个字 ...
- 【PyMuPDF和pdf2image】Python将PDF转成图片
前言: 在最近的测试中遇到一个与PDF相关的测试需求,其中有一个过程是将PDF转换成图片,然后对图片进行测试. 粗略的试了好几种方式,其中语言尝试了Python和Java,总体而言所找到的Python ...
- C# Asp.Net 实现PPT/PDF转成图片(不依赖office)
最近公司有个需求,将PPT课件转成图片列表,然后在前端展示成轮播图,于是一开始通过Microsoft.Office.Interop.PowerPoint包实现了这个需求具体代码如下: /// < ...
- php 将pdf转成图片且将图片拼接
说明: 1.pdf转图片通过安装php扩展imagick实现. 2.由于windows扩展安装的一系列问题,建议在linux环境开发,windows大伙可以尝试安装. 3.为Centos 安装Imag ...
- Java PDF转换成图片并输出给前台展示
首先需要导入所需工具类 <dependency> <groupId>org.apache.pdfbox</groupId> <artifactId>fo ...
- pdf 切割成圖片的方法
/// <summary> /// 将PDF文档转换为图片的方法 /// </summary> /// <param na ...
- pdf转成图片
http://blog.csdn.net/wydhao123/article/details/51596028 jar commons-logging.jar. pdfbox-2.0.1.jar.fo ...
随机推荐
- python 模块库
python mod --------------------os https://segmentfault.com/a/1190000003061079logging ...
- MyBatis原理分析之三:初始化(配置文件读取和解析)
1. 准备工作 编写测试代码(具体请参考<Mybatis入门示例>),设置断点,以Debug模式运行,具体代码如下: )ExecutorType:执行类型,ExecutorType主要有三 ...
- office project 激活
office project 2010激活方式: 图上中,箭头位置,可能没激活,需要软件激活 ( mini-KMS Activator(Office2010激活工具) V1.2 绿色版 ) 激活方式如 ...
- ruby中excel简单操作以及文件读取操作方法
# -*-coding:utf-8 -*-#author:kanlijunrequire 'win32ole'require 'fileutils'class ResultAnalyse @@i=0 ...
- web页面如何播放amr的音频文件
这个需求由来已久,公司的语音订单很多,每次客服都是从服务器down下语音来听.很不方便..于是我就上网扒拉看有么有什么web播放器能播放amr格式的音频文件,amr百度百科 总之找了很久.,,然后发现 ...
- Redis 简单命令
1. 新增 set keyName "keyValue" 2. 获取 get keyName 查看所有Key keys * 3. 删除 //删除当前数据库中的所有Key flush ...
- future
/*T ->return type, E -> error type, D -> parameter type */ template<typename T, typename ...
- npm命令ionic安装失败cordova安装失败解决方法
转载:http://bbs.phonegap100.com/thread-2622-1-1.html 镜像使用方法(三种办法任意一种都能解决问题,建议使用第三种,将配置写死,下次用的时候配置还在): ...
- dedecms 模板静态化
require_once (dirname(__FILE__) . "/../include/common.inc.php"); require_once DEDEINC.&quo ...
- 反人类的MyEclipse之-Javascript双引号自动补全
MyEclipse由于在JavaScript中按下一个双引号后会自动把后面的双引号补全.本人习惯两个双引号一起按下,那么这个时候在编辑器里就会出现三个",这样导致代码错误. 今天就因为MyE ...