2010-06-18 68 views
1

我在我的網頁上顯示的PDF這樣顯示加載圖片時,PDF呈現

<object data="/Customer/GetPricedMaterialPDF?projID=<%= ViewData["ProjectID"]%>" 
    type="application/pdf" width="960" height="900" style="margin-top: -33px;"> 
    <p> 
     It appears you don't have a PDF plugin for this browser. No biggie... you can <a 
      href="/Customer/GetPricedMaterialPDF?projID=<%= ViewData["ProjectID"]%>">click 
      here to download the PDF file. </a> 
    </p> 
</object> 

和控制器的功能是

public FileStreamResult GetPricedMaterialPDF(string projID) 
     { 
      System.IO.Stream fileStream = GeneratePDF(projID); 
      HttpContext.Response.AddHeader("content-disposition", 
       "attachment; filename=form.pdf"); 
      return new FileStreamResult(fileStream, "application/pdf"); 

     } 



private System.IO.Stream GeneratePDF(string projID) 
     { 
      //create your pdf and put it into the stream... pdf variable below 
      //comes from a class I use to write content to PDF files 

      System.IO.MemoryStream ms = new System.IO.MemoryStream(); 
      Project proj = GetProject(projID); 
      List<File> ff = proj.GetFiles(Project_Thin.Folders.IntegrationFiles, true); 
      string fileName = string.Empty; 
      if (ff != null && ff.Count > 0 && ff.Where(p => p.AccessToUserID == CurrentCustomer.CustomerID).Count() > 0) 
      { 
       ff = ff.Where(p => p.AccessToUserID == CurrentCustomer.CustomerID).ToList(); 
       foreach (var item in ff) 
       { 
        fileName = item.FileName; 
       } 

       byte[] bArr = new byte[] { }; 
       bArr = GetJDLFile(fileName); 
       ms.Write(bArr, 0, bArr.Length); 
       ms.Position = 0; 
      } 
      return ms; 
     } 

現在我的問題是關於控制器服用10到20秒鐘處理功能pdf,

data="/Customer/GetPricedMaterialPDF?projID=<%= ViewData["ProjectID"]%>" 

那時我的頁面顯示空白,我不想要。我想在當時顯示加載圖像。 我怎樣才能做到這一點?

+0

爲什麼要設置固定的寬度和高度?例如,如果我的瀏覽器窗口的視口小於900像素高,則PDF應用程序的下半部分將被隱藏,包括滾動條的步進器。 – 2010-06-18 04:56:05

回答

0

如果你把<div>您的網頁上,以較低的z-index<object>元素的準確位置,所以,它是由後者完全覆蓋,你可能會幸運的時只要用戶代理沒有收到任何頭文件(並且不能控制分配給PDF閱讀器的表面),用戶代理就會顯示它。你可以把你的信息或(動畫)圖像放在裏面。

如果將圖像放在<object>旁邊,它將永遠顯示,因爲您無法確定是否已完成PDF文件的傳輸。