Search code examples
c#asp.netasp.net-mvcrotativa

ASP.NET Get bytes of application/pdf attachment


I have this url: https://example.com/getPDF/Index

This method returns an attached application/pdf via Rotativa

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

My Question is how would I call this method and get the bytes from application/pdf file? I do not want to generate the PDF and get the BuildFile method provided by Rotativa to get the bytes.


Solution

  • It looks like you should be able to call BuildFile on the output from ViewAsPdf, like this:

    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
    }