设置.pdf名称,但阻止使用Rotativa进行下载

时间:2016-08-08 12:20:35

标签: c# asp.net-mvc pdf rotativa

我需要在显示之前设置.pdf名称。我试着像这样设置它

return new ViewAsPdf(GetViewName(), "", reportVM) 
{ 
   PageSize = Size.Letter, FileName = GetViewName() + "-" + DateTime.Now.ToShortDateString() + ".pdf"
 }; ,

但是这样会自动下载.pdf。是否可以设置.pdf名称而不是下载?

谢谢!

3 个答案:

答案 0 :(得分:1)

var pdfResult = new Rotativa.PartialViewAsPdf("YourPartialView", model) {
    SaveOnServerPath = path, // Save your place
    PageWidth = 200,
    PageHeight = 350,
};

// This section allows you to save without downloading 

pdfResult.BuildPdf(this.ControllerContext);
return RedirectToAction("Index", "Home");

答案 1 :(得分:1)

Rotativa.AspNetCore.Options.Margins margins = new Rotativa.AspNetCore.Options.Margins(10, 2, 5, 2); 
        return new ViewAsPdf(estimate)
        {
            CustomSwitches = "--viewport-size 1024x768",
            PageMargins = margins,
            FileName = "Estimate -" + estimate.EstimateNumber + ".pdf",
            ContentDisposition = Rotativa.AspNetCore.Options.ContentDisposition.Inline
        }; 

答案 2 :(得分:0)

Response.AppendHeader("Content-Disposition", new System.Net.Mime.ContentDisposition { Inline = true, FileName = "myCorrectlyNamed.pdf" }.ToString());
return new ViewAsPdf(GetViewName(), "", reportVM);