轉帖|使用教程|編輯:李爽夏|2018-10-09 16:43:17.000|閱讀 928 次
概述:Spire.PDFViewer for ASP.NET 用于在ASP.NET Web Form上加載查看PDF文件,并能指定跳轉的頁面,在適應頁面寬度或高度下查看文件,縮放頁面等等。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
第一步,創建一個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(@"Files\Sample1.pdf"); } }
運行程序,先顯示出第一個文件,當切換文件時,在瀏覽器上直接輸入URL,比如 //localhost:6411/WebForm1.aspx?CacheInterval=1000&CacheTime=1200&CacheNumberImage=1000&ScrollInterval=300&file=Sample3.pdf 切換后的結果。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自: