csharp: Cyotek.GhostScript.Pdf Conversion pdf convert image

from:https://www.ghostscript.com/download/gsdnld.html

https://www.codeproject.com/Articles/317700/Convert-a-PDF-into-a-series-of-images-using-Csharp

https://www.cyotek.com/blog/convert-a-pdf-into-a-series-of-images-using-csharp-and-ghostscript

https://github.com/mephraim/ghostscriptsharp   gsdll32.dll,有32位和64位的。把它放在相应的BIN文件夹下。

 https://archive.codeplex.com/?p=ghostscriptnet

https://archive.codeplex.com/?p=ghostscriptstudio

把gsdll32.dll 放在BIN下

 

Safari for Windows 5.1.7 http://appldnld.apple.com/Safari5/041-5487.20120509.INU8B/SafariSetup.exe

1
2
3
4
5
6
7
8
9
10
11
<form id="form1" runat="server">
<div>
    <p>
        <asp:LinkButton runat="server" ID="previousLinkButton" Text="Previous" OnClick="previousLinkButton_Click" />
        <asp:LinkButton runat="server" ID="nextLinkButton" Text="Next" OnClick="nextLinkButton_Click" />
    </p>
    <p>
        <asp:Image runat="server" ID="pdfImage" ImageUrl="~/PdfImage.ashx?fileName=sample.pdf&page=1" />
    </p>
</div>
</form>

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/// <summary>
  ///
  /// </summary>
public partial class _Default : System.Web.UI.Page
{
 
 
    /// <summary>
    ///
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
  protected void previousLinkButton_Click(object sender, EventArgs e)
  {
    this.IncrementPage(-1);
  }
    /// <summary>
    ///
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
  protected void nextLinkButton_Click(object sender, EventArgs e)
  {
    this.IncrementPage(1);
  }
  /// <summary>
  /// /
  /// </summary>
  /// <param name="increment"></param>
  private void IncrementPage(int increment)
  {
    NameValueCollection queryString;
    int pageNumber;
    string pdfFileName;
    Pdf2Image converter;
 
    queryString = HttpUtility.ParseQueryString(pdfImage.ImageUrl.Substring(pdfImage.ImageUrl.IndexOf("?")));
    pdfFileName = queryString["fileName"];
    pageNumber = Convert.ToInt32(queryString["page"]) + increment;
    converter = new Pdf2Image(this.Server.MapPath("~/" + pdfFileName));
 
    if (pageNumber > 0 && pageNumber <= converter.PageCount)
      pdfImage.ImageUrl = string.Format("~/PdfImage.ashx?fileName={0}&page={1}", pdfFileName, pageNumber);
  }

  

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Web;
using Cyotek.GhostScript.PdfConversion;
 
namespace GhostScriptWebTest
{
  public class PdfImage : IHttpHandler
  {
    public void ProcessRequest(HttpContext context)
    {
      string fileName;
      int pageNumber;
      Pdf2Image convertor;
      Bitmap image;
 
      fileName = context.Server.MapPath("~/" + context.Request.QueryString["fileName"]);
      pageNumber = Convert.ToInt32(context.Request.QueryString["page"]);
 
      // convert the image
      convertor = new Pdf2Image(fileName);
      image = convertor.GetImage(pageNumber);
 
      // set the content type
      context.Response.ContentType = "image/jpeg";// "image/png";
 
      // save the image directly to the response stream
      image.Save(context.Response.OutputStream, ImageFormat.Jpeg);  //
    }
 
    public bool IsReusable
    { get { return true; } }
  }
}

  

 

    IE6      

IE 8.0 

Chrome  

Firefox

png

image/x-png

image/x-png

image/png           

image/png

jpg

image/pjpeg

image/jpeg           

image/jpeg            

image/jpeg

jpeg

image/pjpeg

image/pjpeg     

image/jpeg 

image/jpeg

bmp

image/bmp 

 image/bmp            

image/bmp           

image/bmp

posted @   ®Geovin Du Dream Park™  阅读(490)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
历史上的今天:
2016-06-24 csharp:VerifyCode in winform or webform
2015-06-24 csharp:获取 DNS、网关、子网掩码、IP
2015-06-24 csharp: using wininet.dll
2013-06-24 csharp:汉字转带拼音声调
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示