2010-06-18 64 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文件的传输。