How do I display a PDF using PdfSharp in ASP.Net MVC?

后端 未结 2 822
耶瑟儿~
耶瑟儿~ 2021-01-02 11:32

We\'re making an ASP.Net MVC app that needs to be able to generate a PDF and display it to the screen or save it somewhere easy for the user to access. We\'re using PdfSharp

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-02 11:54

    I'm not familar with PDF sharp but for MVC is mostly done via built in functionality. You need to get your pdf document represented as an array of bytes. Then you'd simply use MVC's File method to return it to the browser and let it handle the download. Are there any methods on their class to do that?

    public class PdfDocumentController : Controller
    {
        public ActionResult GenerateReport(ReportPdfInput input)
        {
            //Get document as byte[]
            byte[] documentData;
    
            return File(documentData, "application/pdf");
        }
    
    }
    

提交回复
热议问题