Spire.PDFViewer for ASP.NET 用于在ASP.NET Web Form上加载查看PDF文件,并能指定跳转的页面,在适应页面宽度或高度下查看文件,缩放页面等等。
Spire.PDFViewer for ASP.NET 用于在ASP.NET Web Form上加载查看PDF文件,并能指定跳转的页面,在适应页面宽度或高度下查看文件,缩放页面等等。下面介绍使用的详细步骤:
第一步,创建一个web程序,把Spire dlls引用到项目中。

第二步,把控件添加到工具箱上,点击工具箱,右键选择添加Tab,给控件取名为Spire.PDFViewer

点击Choose Items

选择浏览,找到Spire.PdfViewer.Asp.dll,选中它然后点击OK。

完成添加,控件出现在工具箱上。

点击WebForm.aspx,选择视图设计器,将PdfViewer控件拖动到Form上,并调整宽度和高度,将查看的文件放入文件夹Files。

第三步,在WebForm.aspx.cs文件的相应位置添加代码。注意在加载PDF文件前必须添加判断语句if (!IsPostBack)。
protected void Page_Load(object sender, EventArgs e){ if (!IsPostBack) { //设置清空缓存的时间 this.PdfViewer1.CacheInterval = 1200; //设置缓存时间 this.PdfViewer1.CacheTime = 1000; //设置缓存图片的数量 this.PdfViewer1.CacheNumberImage = 1000; //设置停止滚动响应事件的时间 this.PdfViewer1.ScrollInterval = 300; //设置缩放比例 this.PdfViewer1.ZoomFactor = 1; //加载本地文件夹Files里的文件 this.PdfViewer1.LoadFromFile("Files/Sample1.pdf"); }}
运行项目,结果截图:

下面介绍如何查看files文件夹中的其他文档。代码与查看一个文档有些差别。
if (!IsPostBack){ if (Request.QueryString["file"] != null) { this.PdfViewer1.CacheInterval = ushort.Parse(Request.QueryString["CacheInterval"].ToString()); this.PdfViewer1.CacheTime = ushort.Parse(Request.QueryString["CacheTime"].ToString()); this.PdfViewer1.CacheNumberImage = ushort.Parse(Request.QueryString["CacheNumberImage"].ToString()); this.PdfViewer1.ScrollInterval = ushort.Parse(Request.QueryString["ScrollInterval"].ToString()); this.PdfViewer1.LoadFromFile(@"Files" + Request.QueryString[""file""].ToString()); } else { //设置相关缓存参数 this.PdfViewer1.CacheInterval = 1000; this.PdfViewer1.CacheTime = 1200; this.PdfViewer1.CacheNumberImage = 1000; this.PdfViewer1.ScrollInterval = 300; this.PdfViewer1.LoadFromFile(@""FilesSample1.pdf""); }}
运行程序,先显示出第一个文件,当切换文件时,在浏览器上直接输入URL,比如 http://localhost:6411/WebForm1.aspxacheInterval=1000&CacheTime=1200&CacheNumberImage=1000&ScrollInterval=300&file=Sample3.pdf 切换后的结果。

标签:PDF”
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!