引用

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 切割成图片的更多相关文章

  1. C#技术分享【PDF转换成图片——13种方案】(2013-07-25重新整理)

    原文:C#技术分享[PDF转换成图片--13种方案](2013-07-25重新整理) 重要说明:本博已迁移到 石佳劼的博客,有疑问请到 文章新地址 留言!!! 写在最前面:为了节约大家时间,撸主把最常 ...

  2. C#技术分享【PDF转换成图片——11种方案】

    1.[iTextSharp.dll],C# 开源PDF处理工具,可以任意操作PDF,并可以提取PDF中的文字和图片,但不能直接将PDF转换成图片. DLL和源码 下载地址:http://downloa ...

  3. 在linux环境下使用icepdf或pdfbox将pdf转化成图片是乱码解决

    在linux环境下使用icepdf或pdfbox将pdf转化成图片是出现乱码,网上查发下是itextpdf生成pdf引用"STSong-Light"字体而linux环境下没有这个字 ...

  4. 【PyMuPDF和pdf2image】Python将PDF转成图片

    前言: 在最近的测试中遇到一个与PDF相关的测试需求,其中有一个过程是将PDF转换成图片,然后对图片进行测试. 粗略的试了好几种方式,其中语言尝试了Python和Java,总体而言所找到的Python ...

  5. C# Asp.Net 实现PPT/PDF转成图片(不依赖office)

    最近公司有个需求,将PPT课件转成图片列表,然后在前端展示成轮播图,于是一开始通过Microsoft.Office.Interop.PowerPoint包实现了这个需求具体代码如下: /// < ...

  6. php 将pdf转成图片且将图片拼接

    说明: 1.pdf转图片通过安装php扩展imagick实现. 2.由于windows扩展安装的一系列问题,建议在linux环境开发,windows大伙可以尝试安装. 3.为Centos 安装Imag ...

  7. Java PDF转换成图片并输出给前台展示

    首先需要导入所需工具类 <dependency> <groupId>org.apache.pdfbox</groupId> <artifactId>fo ...

  8. pdf 切割成圖片的方法

    /// <summary>         /// 将PDF文档转换为图片的方法         /// </summary>         /// <param na ...

  9. pdf转成图片

    http://blog.csdn.net/wydhao123/article/details/51596028 jar commons-logging.jar. pdfbox-2.0.1.jar.fo ...

随机推荐

  1. int.Parse()、int.TryParse()和Convert.ToInt32()的区别

    1:int.Parse(一个参数)        此参数必须满足: 1 只能是字符串: 2 只能是 “整型” 字符串,即各种整型ToString()之后的形式,也不能为浮点型. 2:int.TryPa ...

  2. Shell编程之--“grep-awk-sed” 基础用法汇总-菜鸟入门级

  3. 显示intent和隐示intent有什么区别

    显式Intent定义:对于明确指出了目标组件名称的Intent,我们称之为显式Intent. 隐式Intent定义:对于没有明确指出目标组件名称的Intent,则称之为隐式Intent. 说明:And ...

  4. 获取与Url链接相关的信息

    以下结果的值以此示例为基础:http://www.x2y2.com:80/fisker/post/0703/window.location.html?ver=1.0&id=6#imhere j ...

  5. docker网络配置方法总结

    docker启动时,会在宿主主机上创建一个名为docker0的虚拟网络接口,默认选择172.17.42.1/16,一个16位的子网掩码给容器提供了65534个IP地址.docker0只是一个在绑定到这 ...

  6. opencart在空间中安装出错,连接不上mysql

    客户要求,要在国外某空间安装opencart.话说opencart根本没怎么搞过,也不太清楚,php也是半吊子,临时看了几天,硬着头皮上把. 出错,安装进行到数据库连接设置的时候,死活连接不上,开始以 ...

  7. MySQL连接查询的简单概括+思维导图

  8. php5.3到php7.0.x新特性介绍

    <?php /*php5.3*/ echo '<hr>'; const MYTT = 'aaa'; #print_r(get_defined_constants()); /* 5.4 ...

  9. 关于STM32的FLASH操作【转载】

    说到STM32的FLSAH,我们的第一反应是用来装程序的,实际上,STM32的片内FLASH不仅用来装程序,还用来装芯片配置.芯片ID.自举程序等等.当然, FLASH还可以用来装数据. FLASH分 ...

  10. PL/SQL错误提示 database character set(AL32UTF8) and Client character set(ZHS16GBK) are different

    PL/SQL database character set(AL32UTF8) and Client character set(ZHS16GBK) are different 这是由于安装oracl ...