我在我的页面上显示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 :(得分:0)
如果您在页面上<div>
正好位于<object>
元素位置较低的z-index
,那么后者完全覆盖了它,那么您可能会很幸运当用户代理显示它时,只要它没有发送任何标题(并且不会将指定的表面控制到PDF阅读器)。您可以将信息或(动画)图像放入其中。
如果您将图像放在<object>
旁边,它将永久显示,因为您无法确定是否已传输完整的PDF文件。