偶遇需要解析PDF文件为单张图,此做,

http://git.oschina.net/jiailiuyan/OfficeDecoder

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Aspose.Pdf.Devices; namespace Helpers
{
public static class PDFHelper
{ /// <summary> 转换 PDF 的每一页为图片 </summary>
/// <param name="pdffile"></param>
/// <param name="savedirectory"></param>
/// <returns></returns>
public static List<string> ConvertToImages(string pdffile, string savedirectory = "")
{
// 返回的图片绝对路径集合
List<string> images = new List<string>(); // 获取 PDF 文件名称
var pdfname = System.IO.Path.GetFileNameWithoutExtension(pdffile); // 如果指定了保存路径,则使用传入的路径,否则在 PDF 文件的同级创建同名文件夹当作保存路径
savedirectory = string.IsNullOrWhiteSpace(savedirectory) ? System.IO.Path.GetDirectoryName(pdffile) : savedirectory;
savedirectory = System.IO.Path.Combine(savedirectory, pdfname);
// 防止保存的路径不存在因此创建保存文件夹
Directory.CreateDirectory(savedirectory); using (var pdfd = new Aspose.Pdf.Document(pdffile))
{
var count = pdfd.Pages.Count;
// Aspose.Pdf 的单页获取索引从 1 开始
for (int i = ; i <= count; i++)
{
var imagefile = System.IO.Path.Combine(savedirectory, i + ".jpg");
try
{
//图片处理后的存放路径
using (var imageStream = new FileStream(imagefile, FileMode.Create))
{
var resolution = new Resolution();
var jpegDevice = new JpegDevice(resolution, );
jpegDevice.Process(pdfd.Pages[i], imageStream);
imageStream.Close(); images.Add(imagefile);
}
}
catch { }
}
pdfd.Dispose();
} // 返回获取图片后的路径集合
return images;
} }
}

WPF解析PDF为图片的更多相关文章

  1. WPF解析PPT为图片

    偶遇需要解析 PPT为单张图片 其中,对于包含动画的PPT页,分别对动画最后效果进行截取,即每个连续动画截取 (动画N个)N+1(原图)张 http://git.oschina.net/jiailiu ...

  2. WPF解析Word为图片

    偶遇需要解析Word为单张图,此做 http://git.oschina.net/jiailiuyan/OfficeDecoder using System; using System.Collect ...

  3. 使用pdfbox分页保存pdf为图片

    一.背景 pdfbox作为Apache开源的PDF操作工具,允许创建新的PDF文档,操作现有文档,以及从文档中提取内容的能力.Apache PDFBox还包括一些命令行实用工具.本文楼主主要介绍其中的 ...

  4. Python使用PDFMiner解析PDF

    近期在做爬虫时有时会遇到网站只提供pdf的情况,这样就不能使用scrapy直接抓取页面内容了,只能通过解析PDF的方式处理,目前的解决方案大致只有pyPDF和PDFMiner.因为据说PDFMiner ...

  5. C#解析PDF

    C#解析PDF的方式有很多,比较好用的有ITestSharp和PdfBox. PDF内容页如果是图片类型,例如扫描件,则需要进行OCR(光学字符识别). 文本内容的PDF文档,解析的过程中,我目前仅发 ...

  6. pdf 转图片,提取图片研究心得

    1.pdf 中的数据是有多种编码的,详情请看:http://www.cnblogs.com/zendu/p/7644465.html 2.我的工作场景比较特殊,pdf中全部是图片,所以pdf转图片就有 ...

  7. Python3.x:PDFMiner3k在线、本地解析pdf

    Python3.x:PDFMiner3k在线.本地解析pdf 安装 pip install pdfminer3k 示例一:在线解析pdf ''' Demo:pdf2htmlex解析pdf Dateti ...

  8. Python3.x:pdf2htmlEX(解析pdf)安装和使用

    Python3.x:pdf2htmlEX(解析pdf)安装和使用 简介 pdf2htmlEX是一款优秀的pdf转换成html的工具: 下载 windows下载地址:http://soft.rubypd ...

  9. Python|网页转PDF,PDF转图片爬取校园课表~

    import pdfkit import requests from bs4 import BeautifulSoup from PIL import Image from pdf2image imp ...

随机推荐

  1. OS X 10.10 apache配置

    配置内容转自:http://www.linuxidc.com/Linux/2015-04/116347.htm 一.apache的配置 apache已经自带了,只需如下三个命令就可以了. 开启apac ...

  2. Javascript中二级联动

    主要使用到到了地址JSON格式,来做,没有涉及数据库的读取. <!DOCTYPE html><html><head> <meta charset=" ...

  3. flv视频播放器代码

    <div class="txt1"> <script type="text/javascript"> var swf_width=307 ...

  4. Table of Contents - ActiveMQ

    Getting Started ActiveMQ 的安装 Hello World Configuring Standard ActiveMQ Components Connecting to Acti ...

  5. .NET DLL 保护措施详解(四)各操作系统运行情况

    我准备了WEB应用程序及WinForm应用程序,分别在WIN SERVER 2012/2008/2003.Win7/10上实测,以下为实测结果截图: 2012 2008 2003 WIN7 WIN10 ...

  6. C#右键复制路径

    using System;//Environment using System.Windows.Forms; //add referece of System.Windows.Forms :DataF ...

  7. ASP.NET缓存全解析1 转自网络原文作者李天平

    有时候总听到网友说网站运行好慢,不知如何是好:有时候也总见到一些朋友写的网站功能看起来非常好,但访问性能却极其的差.没有“勤俭节约”的意识,势必会造成“铺张浪费”.如何应对这种情况,充分利用系统缓存则 ...

  8. Varnish缓存服务器的搭建配置手册

    Varnish缓存服务器的搭建配置手册 1.Varnish官方环境依赖提示 Installing Varnish Cache is as simple as enabling our package ...

  9. 【Linux C中文函数手册】文件内容控制函数

    文件内容控制函数 1)clearerr 清除文件流的错误旗标 相关函数 feof表头文件 #include<stdio.h>定义函数 void clearerr(FILE * stream ...

  10. ReactiveCocoa比较区分replay, replayLast和replayLazily

    一直搞不清楚replayLazily和replay的区别可以直接跳到最后看. 原文:http://spin.atomicobject.com/2014/06/29/replay-replaylast- ...