将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 ...
随机推荐
- [LeetCode&Python] Problem 371. Sum of Two Integers
Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -. Exam ...
- C#正则表达式语法教程
C#语法之正则 本文提供全流程,中文翻译. Chinar 坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) Chinar -- 心分享.心创新!助力 ...
- PAT-L2-006(根据后序中序遍历建立树)
#include <bits/stdc++.h> using namespace std; ; queue <int> q; int a[N]; int b[N]; int n ...
- P1242 新汉诺塔(搜索+模拟退火)
题目链接:传送门 题目大意: 汉诺塔,给定n个盘子(n <= 45),起始状态和结束状态,求最小的步数以及路径. 思路: 考虑用dfs贪心地将剩余最大盘归位. #include<bits/ ...
- 用requestAnimationFrame优化Web动画
requestAnimationFrame是什么? 在浏览器动画程序中,我们通常使用一个定时器来循环每隔几毫秒移动目标物体一次,来让它动起来.如今有一个好消息,浏览器开发商们决定:“嗨,为什么我们不在 ...
- HDU 1159:Common Subsequence(LCS模板)
Common Subsequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- acm 2084
////////////////////////////////////////////////////////////////////////////////#include<iostream ...
- 20165313 《Java程序设计》第八周学习总结
教材学习总结 线程常用方法 1.start() 2.run()定义线程线程对象被调度之后所执行的操作 3.sleep(int millsecond),必须在try-catch语句块中调用sleep方法 ...
- ios-UITableView无内容时,不显示多余的分隔线
效果如上. 只要补上以下方法: //设置多于的分割线 -(void)setExtraCellLineHidden: (UITableView *)tableView { UIView *view = ...
- LG3978 【[TJOI2015]概率论】
前置:卡特兰数 记\(C_n\)为\(n\)个节点的二叉树的个数,\(C_0=1\),对于\(n \geq 1\),取一个根节点,枚举其左子树大小,有 \[C_n=\sum_{i=0}^{n-1}C_ ...