将Word,PDF文档转化为图片
#region 将Word文档转化为图片
/// <summary>
/// 将Word文档转化为图片
/// </summary>
/// <param name="wordpath">需要转换的word文档的全路径</param>
public void Word_Convert2Image(string wordpath)
{
//第一步:将Word文档转化为Pdf文档(中间过程)
Aspose.Words.Document doc = new Aspose.Words.Document(wordpath);
//生成的pdf的路径
string Pdfpath = Server.MapPath("images") + "Word2Pdf.pdf";
doc.Save(Pdfpath, Aspose.Words.SaveFormat.Pdf); //生成中间文档pdf //第二部:开始把第一步中转化的pdf文档转化为图片
int i = ;
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(Pdfpath);
while (i <= pdfDocument.Pages.Count)
{
if (!string.IsNullOrEmpty(Pdfpath))
{
GetImage(Pdfpath, i);
GC.Collect(); //回收内存
}
i++;
}
//图片转化完成之后,删除中间过程产生的pdf文档
if (File.Exists(Pdfpath))
File.Delete(Pdfpath);
}
#endregion
#region 将pdf转化为图片
/// <summary>
/// 将PDF 相应的页转换为图片
/// </summary>
/// <param name="strPDFpath">PDF 路径</param>
/// <param name="Page">需要转换的页页码</param>
private void GetImage(string strPDFpath, int Page)
{
GC.Collect();
string strSavePath = Server.MapPath("images");
byte[] ImgData = GetImgData(strPDFpath, Page);
MemoryStream ms = new MemoryStream(ImgData, , ImgData.Length);
Bitmap returnImage = (Bitmap)Bitmap.FromStream(ms);
string picName=string.Format("{0}_{1}.jpg", CreatePicName(),Page);
string strImgPath = Path.Combine(strSavePath, picName); //图片名称可在此修改
returnImage.Save(strImgPath);
returnImage.Dispose();
ms.Dispose();
AddImage(Page, picName); //将图片添加到数据库
}
/// <summary>
/// 从PDF中获取首页的图片
/// </summary>
/// <param name="PDFPath">PDF 文件路径</param>
/// <param name="Page">需要获取的第几页</param>
/// <returns></returns>
private byte[] GetImgData(string PDFPath, int Page)
{
System.Drawing.Image img = PDFView.ConvertPDF.PDFConvert.GetPageFromPDF(PDFPath, Page, , "", true);
return GetDataByImg(img);//读取img的数据并返回
}
/// <summary>
/// 将单页的PDF转换为图片
/// </summary>
/// <param name="_image"></param>
/// <returns></returns>
private byte[] GetDataByImg(System.Drawing.Image _image)
{
System.IO.MemoryStream Ms = new MemoryStream();
_image.Save(Ms, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] imgdata = new byte[Ms.Length];
Ms.Position = ;
Ms.Read(imgdata, , Convert.ToInt32(Ms.Length));
Ms.Close();
return imgdata;
}
#endregion
将Word,PDF文档转化为图片的更多相关文章
- 第一节:python提取PDF文档中的图片
		
由于项目需要将PDF文档当中的图片转换成图片,所以参考了这篇文章https://blog.csdn.net/qq_15969343/article/details/81673302后项目得以解决. 1 ...
 - PDF文档转PNG图片 c++(转载)
		
PDF文档转PNG图片 c++,例子是转载的,忘记出处了.被我收集起来了. 链接:https://pan.baidu.com/s/1iuxDHibQnvx0UYJ5m25NAg 密码:5o0c
 - java实现MsOffice文档向pdf文档转化
		
本篇文档实现功能,将word和ppt文档的文件转化成pdf格式的文档 应用到jacob 第一步:下载压缩包 (1)jacob官网下载jacob压缩包 (2)网址:http://sourceforge. ...
 - php解析word,获得文档中的图片
		
背景 前段时间在写一个功能:用原生php将获得word中的内容并导入到网站系统中.因为文档中存在公式,图片,表格等,因此写的比较麻烦. 思路 大体思路是先将word中格式为doc的文档转化为docx, ...
 - iOS - 开发中加载本地word/pdf文档说明
		
最近项目中要加载一个本地的word/pdf等文件比如<用户隐私政策><用户注册说明>,有两种方法加载 > 用QLPreviewController控制器实现 步骤 : & ...
 - 如何使用免费PDF控件从PDF文档中提取文本和图片
		
如何使用免费PDF控件从PDF文档中提取文本和图片 概要 现在手头的项目有一个需求是从PDF文档中提取文本和图片,我以前也使用过像iTextSharp, PDFBox 这些免费的PD ...
 - 常用PDF文档开发库
		
C++库: 1,PDF类库 PoDoFo http://podofo.sourceforge.net/ PoDoFo 是一个用来操作 PDF 文件格式的 C++ 类库.它还包含一些小工具用来解析 ...
 - Apache PDFbox开发指南之PDF文档读取
		
转载请注明来源:http://blog.csdn.net/loongshawn/article/details/51542309 相关文章: <Apache PDFbox开发指南之PDF文本内容 ...
 - Aspose.Words操作word生成PDF文档
		
Aspose.Words操作word生成PDF文档 using Aspose.Words; using System; using System.Collections.Generic; using ...
 
随机推荐
- 【leeetcode】125-Valid Palindrome
			
problem 125. Valid Palindrome 参考 1. Leetcode_Valid Palindrome; 完
 - 关于Linux前后台进程切换
			
前言: 当使用SSH远程登录服务器时,对于运行时间较长的程序(如Caffe的训练可能需要十几个小时), SSH可能会在很长时间后断掉,导致程序没运行完就中断了. 为了解决这个问题,需要将在服务器运行的 ...
 - BZOJ-5244 最大真因数(min25筛)
			
题意:一个数的真因数指不包括其本身的所有因数,给定L,R,求这个区间的所有数的最大真因数之和. 思路:min25筛可以求出所有最小因子为p的数的个数,有可以求出最小因子为p的所有数之和. 那么此题就是 ...
 - a标签总结
			
一.<a>定义和用法 <a> 标签定义超链接,用于从一张页面链接到另一张页面. <a> 元素最重要的属性是 href 属性,它指示链接的目标. 在所有浏览器中 ...
 - hdu-2196 树形dp   求一个树中所有节点能到达的最远距离f[i] (其实也不难嘛!)
			
#include <bits/stdc++.h> using namespace std; ; struct T { int to; int w; }; vector < vecto ...
 - root/base/stem概念
			
The verb root (or base form): 1.is the same as the infinitive不定式 (e.g., to dive, to jump, to wonder) ...
 - pip3 install scrap报错
			
mac系统 pip3 install scrapy 失败 No local packages or working download links found for incremental>=1 ...
 - 2017.7.11  fuse工作原理
			
FUSE的工作原理如图所示.假设基于FUSE的用户态文件系统hello挂载在/tmp/fuse目录下.当应用层程序要访问/tmp/fuse下的文件时,通过glibc中的函数进行系统调用,处理这些系统调 ...
 - Python知识点整理,基础1 - 基本语法
 - DBUtils和连接池
			
今日内容介绍 1.DBUtils 2.连接池 ###01DButils工具类的介绍个三个核心类 * A: DButils工具类的介绍个三个核心类 * a: 概述 * DBUtils是java编程中的数 ...