用的是破解版的 O2S.Components.PDFRender4NET.dll 插件, 简单引用即可

    public static class PdfToImage
{
public static MemoryStream GetPdfImagePageStream(string pdfInputPath, int pageIndex, ImageFormat format, int width = , int height = , int quality = )
{
try
{
//pdf处理插件
PDFFile pdfFile = PDFFile.Open(pdfInputPath);
int total = pdfFile.PageCount; #region 防止异常参数
if (pageIndex < )
{
pageIndex = ;
}
if (pageIndex > total)
{
pageIndex = total - ;
}
if (quality < )
{
quality = ;
}
if (quality > )
{
quality = ;
}
if (width <= )
{
width = ;
} if (height <= )
{
height = ;
}
#endregion //pdf转换图片
SizeF pageSize = pdfFile.GetPageSize(pageIndex); Bitmap pageImage = pdfFile.GetPageImage(pageIndex, * quality); MemoryStream ms = new MemoryStream(); pageImage.Save(ms, format); //原图
Image img = Image.FromStream(ms, true); double ratio = (double)width / (double)height; double oRatio = (double)img.Width / (double)img.Height; int sbWidth = ; int sbHeight = ; int outX = ;
int outY = ; if (oRatio < ratio)
{
sbWidth = (int)(img.Width * ((double)height / (double)(img.Height)));
sbHeight = height; outX = (width - sbWidth) / ;
}
else
{
sbHeight = (int)(img.Height * ((double)width / (double)(img.Width)));
sbWidth = width; outY = (height - sbHeight) / ;
} //缩放
Image sbImg = new Bitmap(sbWidth, sbHeight);
Graphics sbGra = Graphics.FromImage(sbImg);
sbGra.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
sbGra.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
sbGra.Clear(Color.White);
sbGra.DrawImage(img, new System.Drawing.Rectangle(, , sbWidth, sbHeight), new System.Drawing.Rectangle(, , img.Width, img.Height), System.Drawing.GraphicsUnit.Pixel); //补白
Image outImg = new System.Drawing.Bitmap(width, height);
Graphics outGra = System.Drawing.Graphics.FromImage(outImg);
outGra.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
outGra.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
outGra.Clear(Color.White);
outGra.DrawImage(sbImg, new System.Drawing.Rectangle(outX, outY, sbWidth, sbHeight), new System.Drawing.Rectangle(, , sbWidth, sbHeight), System.Drawing.GraphicsUnit.Pixel); MemoryStream outMs = new MemoryStream(); outImg.Save(outMs, format); sbImg.Dispose();
outImg.Dispose();
img.Dispose(); return outMs; }
catch (Exception ex)
{ } return new MemoryStream();
} public static MemoryStream GetPdfImagePageStream(Stream stream, int pageIndex, ImageFormat format, int width = , int height = , int quality = )
{
try
{
//pdf处理插件
PDFFile pdfFile = PDFFile.Open(stream);
int total = pdfFile.PageCount; #region 防止异常参数
if (pageIndex < )
{
pageIndex = ;
}
if (pageIndex > total)
{
pageIndex = total - ;
}
if (quality < )
{
quality = ;
}
if (quality > )
{
quality = ;
}
if (width <= )
{
width = ;
} if (height <= )
{
height = ;
}
#endregion //pdf转换图片
SizeF pageSize = pdfFile.GetPageSize(pageIndex); Bitmap pageImage = pdfFile.GetPageImage(pageIndex, * quality); MemoryStream ms = new MemoryStream(); pageImage.Save(ms, format); //原图
Image img = Image.FromStream(ms, true); double ratio = (double)width / (double)height; double oRatio = (double)img.Width / (double)img.Height; int sbWidth = ; int sbHeight = ; int outX = ;
int outY = ; if (oRatio < ratio)
{
sbWidth = (int)(img.Width * ((double)height / (double)(img.Height)));
sbHeight = height; outX = (width - sbWidth) / ;
}
else
{
sbHeight = (int)(img.Height * ((double)width / (double)(img.Width)));
sbWidth = width; outY = (height - sbHeight) / ;
} //缩放
Image sbImg = new Bitmap(sbWidth, sbHeight);
Graphics sbGra = Graphics.FromImage(sbImg);
sbGra.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
sbGra.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
sbGra.Clear(Color.White);
sbGra.DrawImage(img, new System.Drawing.Rectangle(, , sbWidth, sbHeight), new System.Drawing.Rectangle(, , img.Width, img.Height), System.Drawing.GraphicsUnit.Pixel); //补白
Image outImg = new System.Drawing.Bitmap(width, height);
Graphics outGra = System.Drawing.Graphics.FromImage(outImg);
outGra.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
outGra.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
outGra.Clear(Color.White);
outGra.DrawImage(sbImg, new System.Drawing.Rectangle(outX, outY, sbWidth, sbHeight), new System.Drawing.Rectangle(, , sbWidth, sbHeight), System.Drawing.GraphicsUnit.Pixel); MemoryStream outMs = new MemoryStream(); outImg.Save(outMs, format); sbImg.Dispose();
outImg.Dispose();
img.Dispose(); return outMs; }
catch (Exception ex)
{ } return new MemoryStream();
}
}

DLL下载: O2S.Components.PDFRender4NET.dll

.Net的PDF转图片的更多相关文章

  1. C# 给PDF添加图片背景

    C# 给PDF添加图片背景 今天要实现的是给PDF文件添加图片背景这个功能.PDF是近年来最流行的文件之一,无论是办公还是日常生活中都经常会用到,很多时候,PDF文件的背景色都是白色,看多了难免觉得累 ...

  2. C# 第三方DLL,可以实现PDF转图片,支持32位系统、64位系统

    itextsharp.dll,是一个开源的在C#中用来生成PDF文档的库文件,不少C#爱好者用它制作出了PDF文档生成器.使用时只需在你的C#项目中添加引入此组件即可,使用方法网上有很多,自己查阅一下 ...

  3. PDF转图片 C# with Adobe API

    PDF转图片大概有十几种方式,褒贬不一,我就详细给大家说一下我认为效率最高的方式,使用Adobe官方的SDK 安装acrobat reader 9.0以上即可,勾选如下组件.

  4. 在线提取PDF中图片和文字

    无需下载软件,你就可以在线提取PDF中图片和文字,http://www.extractpdf.com/不仅可以获取本地PDF文档的图片和文字,还能获取远程PDF文档的图片和文字.如下图所示:结果本人测 ...

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

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

  6. JAVA中pdf转图片的方法

    JAVA中实现pdf转图片可以通过第三方提供的架包,这里介绍几种常用的,可以根据自身需求选择使用. 一.icepdf.有收费版和开源版,几种方法里最推荐的.转换的效果比较好,能识别我手头文件中的中文, ...

  7. 【JAVA】pdf转图片

    最近java项目中使用到了pdf转图片的需求,在此记录一下. 1.基于GhostScript p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px ...

  8. PDF转图片工具

    点击下载( 提取码:1ll1 ) 软件功能基于mupdf,UI使用wxpython开发 功能: 支持pdf转图片,图片格式png 支持批量转换 使用: 第一步,点击按钮添加文档到列表,或直接将待转换文 ...

  9. Ubuntu下pdf和图片互转

    前边文章可以将ppt转换为pdf  查看 使用unoconv将ppt转为pdf,再使用imagemagick将pdf转为图片 这次想将pdf和图片进行互转 当前目录下只有2.ppt 1.ppt转pdf ...

随机推荐

  1. Access to the path '....' is denied.解决方法

    昨天公司项目迁移服务器,从自己服务器迁移到阿里云服务器,部署完成后发现有一个页面要读取磁盘上的静态文件就报错了... 如图: 解决办法: 在 Web.Config 的 <System.Web&g ...

  2. input事件以及中文输入法的处理

    在项目的开发过程中,相信大家都处理过监听用户输入的事情,一般我们会用到onkeyup.onkeydown.onkeypress.onchange.oninput事件,虽然都很熟悉了,但是还是有必要巩固 ...

  3. OC基础 文件管理

    OC基础  文件管理 1.文件管理类NSFileManager对象的创建: NSFileManager *fm = [NSFileManager defaultManager]; 2.文件操作: (1 ...

  4. C#字节byte类型读取与写入

    //创建文件 //File.Create(@"D:\a.txt"); //Console.WriteLine("创建成功"); ////删除文件 //File. ...

  5. title滚动

    代码: <html><head><title>滚动的文字在TITLE栏上不停滚动</title><script language=javascri ...

  6. mysql定时执行及延时执行,实现类似sql server waitfor功能

    熟悉SQL Server的人都知道,它有一个很有用的功能,waitfor time和waitfor delay,前者表示在某个时间执行,后者表示等待多长时间执行.在我们测试功能和定时执行的时候特别有用 ...

  7. css3之background

    background background: (1)url(image1.png) right bottom, (2)url(image2.png) center, (3)url(image3.png ...

  8. JavaWeb学习笔记--Listener

    JSP中的监听器   Web程序在服务器运行的过程中,程序内部会发生多事件,如Web应用的启动和停止.Session会话的开始和销毁.用户请求的开始和结束等等.有时程序员需要在这些事件发生的时机执行一 ...

  9. 成为IT精英,我奋斗了7年

    成为IT精英,我奋斗了7年 这些日子 我一直在写一个实时操作系统内核,已有小成了,等写完我会全部公开,希望能够为国内IT的发展尽自己一份微薄的力量.最近看到很多学生朋友和我当年一样没有方向 ,所以把我 ...

  10. WCF-基本知识

    WCF-基本知识 (1)WCF服务元数据交换方式介绍: WCF服务有两种方案可以发布自己的元数据.一种是基于HTTP-GET协议提供元数据:另一种则为MEX终结点元数据交换方式,和WCF服务一样使用一 ...