csharp: Cyotek.GhostScript.Pdf Conversion pdf convert image

from:https://www.ghostscript.com/download/gsdnld.htmlhttps://www.codeproject.com/Articles/317700/Convert-a-PDF-into-a-series-of-images-using-Csharphttps://www.cyotek.com/blog/convert-a-pdf-into-a-series-of-images-using-csharp-and-ghostscripthttps://github.com/mephraim/ghostscriptsharp   gsdll32.dll,有32位和64位的。把它放在相应的BIN文件夹下。https://archive.codeplex.com/?p=ghostscriptnethttps://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<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>/// <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); }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; } } }}IE6IE 8.0ChromeFirefoxpngimage/x-pngimage/x-pngimage/pngimage/pngjpgimage/pjpegimage/jpegimage/jpegimage/jpegjpegimage/pjpegimage/pjpegimage/jpegimage/jpegbmpimage/bmpimage/bmpimage/bmpimage/bmp

(0)

相关推荐