2013-07-22 33 views
0

我正在使用MVC3和evopdf(http://www.evopdf.com/)在用戶單擊打印按鈕時創建PDF。mvc3和evopdf - 在生成pdf時顯示「處理」消息

我有初始視圖,其中包含一個窗體和打印按鈕和專門爲打印設計的第二個視圖。

點擊打印按鈕調用JavaScript提交表單,該表單調用打印操作。

我想要發生的是,一旦點擊了打印按鈕,就會顯示「處理」消息。 一旦生成pdf,我希望消息被刪除。

這是JavaScript(我沒有將我的所有的JavaScript的,因爲有不相關的部分)

$(document).ready(function() { 
    $(".btn").click(function() { 
     var delay = 10; 
     $("#AjaxDelay").val(delay); 

     $.blockUI(); 
     $('#printForm').submit(); 
    }); 

    $('#printForm').submit(function() { 
     $.blockUI();  
     $.ajax({ 
      url: this.action, 
      type: this.method,   
      success: function (data) { 
       $.unblockUI(); 
       //I need to open the pdf in appropriate app, adobe pdf viewer or similar 
      }, 
      failure:function(data) { 
       alert("error"); 
       $.unblockUI(); 
      } 
     }); 
     return false; 
    }); 

}); 

形式

@using (Html.BeginForm("PrintView", "Index", new { format = "pdf/", id = Model.ID,  AjaxDelay = Model.AjaxDelay }, FormMethod.Get, new { id="printForm" })) 
{ 
    @Html.HiddenFor(m=>m.AjaxDelay)   
    <button type="button" class="btn print" >Print</button>   
} 

的IndexController

public ActionResult PrintView(int id) 
{   
    var model = GetData(id); 
    return View(model); 
} 

這是我的HttpHandler

public void ProcessRequest(HttpContext context) 
{ 
    if (!context.Request.IsAuthenticated) return;  
    ProducePDF(context, "pdf title", 20); 
} 

private void ProducePDF(HttpContext context, string title,int delay) 
{ 
    var pdfConverter = GetPdfConverter(); 

    // set the license key 
    pdfConverter.LicenseKey = "licence key here"; 
    pdfConverter.JavaScriptEnabled = true; 

    var pdfBytes = pdfConverter.GetPdfBytesFromUrl(context.Request.Url.ToString().Replace(".pdf/", "")); 

    // send the PDF document as a response to the browser for download 
    var response = HttpContext.Current.Response; 
    response.Clear(); 
    response.AddHeader("Content-Type", "application/pdf"); 
    response.AddHeader("Content-Disposition", String.Format("attachment; filename=" + title + ".pdf; size={0}", pdfBytes.Length)); 
    response.BinaryWrite(pdfBytes); 
    response.End(); 
} 

謝謝。

回答