ASP.NET 获取 application/pdf 个附件的字节

ASP.NET Get bytes of application/pdf attachment

我有这个url:https://example.com/getPDF/Index

此方法 returns 附加 application/pdf 通过 Rotativa

public ActionResult RedBluePDF(string community, string procedure) 
{ 
     var model = new GeneratePDFModel(); 
     return new Rotativa.ViewAsPdf("GeneratePDF", model){
          FileName = "TestViewAsPdf.pdf"
     }
}

我的问题是如何调用此方法并从 application/pdf 文件中获取字节?我不想生成PDF并获取Rotativa提供的BuildFile方法来获取字节。

看起来您应该能够在 ViewAsPdf 的输出上调用 BuildFile,如下所示:

public ActionResult RedBluePDF(string community, string procedure) 
{ 
   var model = new GeneratePDFModel(); 
   var pdf= new Rotativa.ViewAsPdf("GeneratePDF", model){
        FileName = "TestViewAsPdf.pdf"
   }
   var bytes = pdf.BuildFile(); // byte array
   // do what you want with the byte array here
}

如果BuildFile()不工作,那么尝试BuildPdf()如下,

public ActionResult RedBluePDF(string community, string procedure) 
{ 
     var model = new GeneratePDFModel(); 

      var pdf= new Rotativa.ViewAsPdf("GeneratePDF", model){
        FileName = "TestViewAsPdf.pdf"
   }

  var bytes = pdf.BuildPdf(ControllerContext);
}