ASP.NET 获取应用程序/pdf 附件的字节数



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

此方法通过 Rotativa 返回附加的应用程序/pdf

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

我的问题是我将如何调用此方法并从应用程序/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);
}

最新更新