pdf转图片记录

1 winform将pdf转图片,有案例,连接为:https://download.csdn.net/download/mingjing941018/20216747

2 Asp.net MVC将pdf转图片

使用Nuget安装包安装Freespire.pdf,控制器中相关代码:

/// <summary>/// 将本地的pdf文件保存为图片/// </summary>/// <param name="pdfName"></param>/// <returns></returns>[HttpPost]public ActionResult GetPdtPic(string folder, string pdfName){try{string bPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "Content\\tjbg";string bFileName = pdfName + ".pdf";string bPdfPath = $"{bPath}\\{folder}\\{bFileName}";//var pdf = PdfDocument.Load(bPdfPath);PdfDocument pdf = new PdfDocument();pdf.LoadFromFile(bPdfPath);var pdfpage = pdf.Pages.Count;//var pagesizes = pdf.PageSizes;for (int i = 1; i <= pdfpage; i++){//Size size = new Size();//size.Height = (int)pagesizes[(i - 1)].Height;//size.Width = (int)pagesizes[(i - 1)].Width;可以把".jpg"写成其他形式//RenderPage(bPdfPath, i, size, bPath + "\\" + i.ToString() + @".jpg", "");Image bImg = pdf.SaveAsImage(i);MemoryStream imgstream = new MemoryStream();bImg.Save(imgstream, ImageFormat.Jpeg);byte[] byData = new Byte[imgstream.Length];imgstream.Position = 0;imgstream.Read(byData, 0, byData.Length);imgstream.Close();//base64 = Convert.ToBase64String(byData);System.Drawing.Image bmp = System.Drawing.Image.FromStream(imgstream);string fileName = string.Format(i.ToString() + @".jpg");bmp.Save(bPath + "\\"+folder+"\\" + fileName, System.Drawing.Imaging.ImageFormat.Jpeg);}pdf.Dispose();return Json(new { Code = 0,Msg = "",Count = pdfpage });}catch (Exception e) {return Json(new { Code = -1,Msg = e.Message,Count = 0 });}}

执行后提示:Spire.PDF Free version is limited to 10 pages of PDF. This limitation is enforced during loading and creating files.When converting PDF to Image, the first 3 pages of PDF files will be converted to Image format successfully。

3 使用magick.net-Q16-AnyCPU进行转换,速度太慢,绝对不能用,网上有资料说这个只能转gif图片,未进行验证

相关代码:

try{string bPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "Content\\tjbg";string bFileName = pdfName + ".pdf";string bPdfPath = $"{bPath}\\{folder}\\{bFileName}";int bCount = 0;MagickReadSettings settings = new MagickReadSettings();settings.Density = new Density(900, 900); //设置质量using (MagickImageCollection images = new MagickImageCollection()){images.Read(bPdfPath, settings);bCount = images.Count;for (int i = 0; i < bCount; i++){MagickImage image = (MagickImage)images[i];image.Format = MagickFormat.Jpeg;string fileName = string.Format(i.ToString() + @".jpg");image.Write(bPath + "\\" + folder + "\\" + fileName);}}return Json(new { Code = 0, Msg = "", Count = bCount });}catch (Exception ex){return Json(new { Code = -1, Msg = ex.Message, Count = 0 });}

4 使用Aspose.PDF.dll进行转换

相关代码:

try{string bPath = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "Content\\tjbg";string bFileName = pdfName + ".pdf";string bPdfPath = $"{bPath}\\{folder}\\{bFileName}";Document pdfDocument = new Document(bPdfPath);int bCount = pdfDocument.Pages.Count;for (int pageCount = 1; pageCount <= bCount; pageCount++){string fileName = string.Format(pageCount.ToString() + @".jpg");using (FileStream imageStream = new FileStream(bPath + "\\" + folder + "\\" + fileName, FileMode.Create)){// Create PNG device with specified attributes// Width, Height, Resolution, Quality// Quality [0-100], 100 is Maximum// Create Resolution objectResolution resolution = new Resolution(300);PngDevice pngDevice = new PngDevice(resolution);// Convert a particular page and save the image to streampngDevice.Process(pdfDocument.Pages[pageCount], imageStream);// Close streamimageStream.Close();}}return Json(new { Code = 0, Msg = "", Count = bCount });}catch (Exception ex){return Json(new { Code = -1, Msg = ex.Message, Count = 0 });}

执行后提示:At most 4 elements (for any collection) can be viewed in evaluation mode

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/442084.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【基础知识】大数据组件HBase简述

HBase是一个开源的、面向列&#xff08;Column-Oriented&#xff09;、适合存储海量非结构化数据或半结构化数据的、具备高可靠性、高性能、可灵活扩展伸缩的、支持实时数据读写的分布式存储系统。 只是面向列&#xff0c;不是列式存储 mysql vs hbase vs clickhouse HMaster …

改变定时器获取传感器频度_广东梅州梅县压力传感器*校对

广东梅州梅县压力传感器*校对看门狗寄存器不会改变或改变不大&#xff0c;如果看门狗寄存器发生了改变或改变很大&#xff0c;则说明系统陷入“死循环”.需要进行出错处理。在工业应用中&#xff0c;严重的干扰有时会破坏中断方式控制字&#xff0c;关闭中断&#xff0c;造成看…

**【POJ - 2389】 Bull Math (高精度乘法)

题干&#xff1a; Bulls are so much better at math than the cows. They can multiply huge integers together and get perfectly precise answers ... or so they say. Farmer John wonders if their answers are correct. Help him check the bulls answers. Read in two …

nodeType的类型

1&#xff1a;元素节点   2&#xff1a;属性节点   3&#xff1a;文本节点   4&#xff1a;CDATA区段   5&#xff1a;实体应用元素   6&#xff1a;实体   7&#xff1a;表示处理指令   8&#xff1a;注释节点   9&#xff1a;最外层的Root element,包括所有其…

springboot 不响应字段为空_面试官扎心一问:Tomcat 在 SpringBoot 中是如何启动的?...

作者&#xff1a;木木匠 http://my.oschina.net/luozhou/blog/3088908前言我们知道 SpringBoot 给我们带来了一个全新的开发体验&#xff0c;我们可以直接把 web 程序达成 jar 包&#xff0c;直接启动&#xff0c;这就得益于 SpringBoot 内置了容器&#xff0c;可以直接启动&am…

【POJ - 3250 】Bad Hair Day (单调栈)

题干&#xff1a; Some of Farmer Johns N cows (1 ≤ N ≤ 80,000) are having a bad hair day! Since each cow is self-conscious about her messy hairstyle, FJ wants to count the number of other cows that can see the top of other cows heads. Each cow i has a s…

a1708硬盘转接口_资讯:希捷上架新款银河Exos系列机械硬盘,15000转+SAS协议

今日最新消息&#xff0c;希捷上架一款新品希捷银河Exos系列机械硬盘。据悉这款硬盘采用了SAS协议&#xff0c;转速高达15000RPM&#xff0c;目前公布的售价600GB为1899元RMB。据官方介绍这款希捷银河Exos系列机械硬盘为2.5英寸&#xff0c;15mm的厚度&#xff0c;最高的转速可…

ACM中关于计算几何(浮点数)的精度问题

计算几何的精度问题说到底其实是浮点数的精度问题&#xff0c;但我觉得“计算几何”比“浮点数”更能吸引眼球&#xff0c;所以选了这个标题。 1.浮点数为啥会有精度问题&#xff1a; 浮点数(以C/C为准)&#xff0c;一般用的较多的是float, double。 占字节数 数值范围 十进…

微信公众号网站开发相关记录

1 如何监听微信录音是否正常开启 wx.startRecord({success: function (ret) {alert("开始录音" JSON.stringify(ret));},fail: function (err) {alert("无法录音" JSON.stringify(err));}});

【POJ - 1182】 食物链(附超详细讲解)(并查集--种类并查集经典题)

题干&#xff1a; 动物王国中有三类动物A,B,C&#xff0c;这三类动物的食物链构成了有趣的环形。A吃B&#xff0c; B吃C&#xff0c;C吃A。 现有N个动物&#xff0c;以1&#xff0d;N编号。每个动物都是A,B,C中的一种&#xff0c;但是我们并不知道它到底是哪一种。 有人用两…

腐蚀单机怎么进_暖气片堵塞是什么原因?要怎么解决呢?

你知道散热器到底为什么堵塞吗&#xff1f;散热器堵塞了怎么办&#xff1f;下面和金旗舰散热器小编一起来看看吧~一、散热器堵塞怎么办首先&#xff0c;把进回水阀先全部关闭&#xff0c;用扳手将散热器的堵头轻轻拧开。这里需要注意的是&#xff0c;堵头对应的散热器下面要放一…

layui弹出界面空白页问题

弹出界面时&#xff0c;有时会出现空白界面&#xff0c;应该如何处理&#xff1f; 1 尝试解决方式&#xff1a;在open方法的success回调方法中&#xff0c;获取当前iframe高度&#xff0c;重新赋予新的高度&#xff1b; let ifr layero.find(iframe)[0]; let bHeight ifr.s…

vspy如何在图形面板显示报文_设备实时状态监控:如何进行工业生产设备数据采集?...

设备实时状态监控&#xff1a;如何进行工业生产设备数据采集&#xff1f;数据采集(DAQ)&#xff0c;是指从传感器和其它待测设备等模拟和数字被测单元中自动采集非电量或者电量信号,送到上位机中进行分析&#xff0c;处理。慧都设备数据采集系统解决方案工业生产设备数据采集是…

【POJ - 2236】Wireless Network (并查集)

题干&#xff1a; An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wireless network with the lap computers, but an unexpected aftershock attacked, all computers in the network were all broken. The computers …

如何使用微信公众平台测试号进行系统开发

申请一个测试号&#xff1a;入口修改测试公众号自定义菜单&#xff08;使用微信公众平台接口调试工具&#xff09;网站开发&#xff0c;进行部署网站测试

【POJ - 1751】Highways (最小生成树)

题干&#xff1a; The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has a very poor system of public highways. The Flatopian government is aware of this problem and has already constructed a number of highways connecting some of the …

jupyter怎么安装jieba_AI工具:Anaconda中Jupyter不能import已安装module问题解决

jupyter模式下写代码时,通过pip install package命令行安装package完成之后,无法在jupyter模式下import &#xff0c;这是个通用的问题&#xff0c;我这里遇到的是import jieba&#xff0c;可能import 别的package也会出现&#xff0c;记录下&#xff0c;也花了点时间排查。。。…

Sql Server数据库设置一个账户只能看到一个数据库

1 新建登录名&#xff0c;注意不要设置用户映射&#xff0c;服务器角色只选择public&#xff08;默认必选&#xff0c;无法去掉&#xff0c;可以添加其他服务器角色&#xff0c;但是不要添加查看所有数据库的权限&#xff0c;接下来会去掉public的查看所有数据库权限&#xff0…

boot lib分离 spring_spring boot + gradle打包bootJar分离lib

以前项目打包一直是用的maven&#xff0c;最近新开一个项目&#xff0c;使用的是spring boot 2.11 gradle 4.10.3&#xff0c;在打包的时候分离lib折腾了好几天&#xff0c;网上找了很多方法都不成功&#xff0c;老是卡在configurations.compile这里&#xff0c;总是获取不到正…

【POJ - 3494】Largest Submatrix of All 1’s(加一点思维后化成 单调栈)

题干&#xff1a; Given a m-by-n (0,1)-matrix, of all its submatrices of all 1’s which is the largest? By largest we mean that the submatrix has the most elements. Input The input contains multiple test cases. Each test case begins with m and n (1 ≤ m…