"
首先你将需要 Cyotek.GhostScript 与 Cyotek.GhostScript.PdfConversion.zip
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="GhostScriptWebTest._Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>PDF Conversion Example</title> </head> <body> <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> </body> </html>
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/png"; // save the image directly to the response stream image.Save(context.Response.OutputStream, ImageFormat.Png); } public bool IsReusable { get { return true; } } } }
using System; using System.Collections.Specialized; using System.Web; using Cyotek.GhostScript.PdfConversion; namespace GhostScriptWebTest { public partial class _Default : System.Web.UI.Page { protected void previousLinkButton_Click(object sender, EventArgs e) { this.IncrementPage(-1); } protected void nextLinkButton_Click(object sender, EventArgs e) { this.IncrementPage(1); } 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.在浏览器中打开pdf文件?
//直接提供PDF文件下载功能即可,浏览器自带对了PDF的打开和查阅工具
2.将PDF转换为一张张的图片在WEB中显示?
######1,你说的虽然可以,但是麻烦了,用户可能打开网页就能看到 2,对,就是这个意思######直接打开PDF是好,但如果这样的话,很大程度是资源保密性就不好了,谁都能下到原版。
一般的做法是用flash来做,需要embed,还要actionscript和javascript交互,挺繁琐的,楼主的方法不错。不知道有没有java的?
######尝试了下,没有 gsdll32.dll ,网上下载的几个貌似版本不对,提示
“无法在 DLL“gsdll32.dll”中找到名为“gsapi_new_instance”的入口点。”
######icepdf不是很好么######win7下实验不成功" ![image.png](https://ucc.alicdn.com/pic/developer-ecology/1511fa18263d480b9ec4d61ff13d2a9b.png)版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。