How to convert pdf Byte[] Array to downloadable file using iTextSharp

后端 未结 1 709
清酒与你
清酒与你 2020-12-14 09:35

Hei guys I have this byte array i want to convert to pdf and make it available for download. Anybody has any idea how this is done?

here is my Action Controller

相关标签:
1条回答
  • 2020-12-14 09:48

    I am using similar code with a few differences:

    Response.Clear();
    MemoryStream ms = new MemoryStream(pdfByte);
    Response.ContentType = "application/pdf";
    Response.AddHeader("content-disposition", "attachment;filename=labtest.pdf");
    Response.Buffer = true;
    ms.WriteTo(Response.OutputStream);
    Response.End();
    
    1. Call Reponse.Clear() earlier.
    2. Use MemoryStream.WriteTo to write to Response.OutputStream.

    Edit: sorry, I didn't see that you are using ASP.NET MVC, the above code is in a WebForms aspx page.

    For ASP.NET MVC, couldn't you just do

    return new FileStreamResult(ms, "application/pdf");
    

    ?

    0 讨论(0)
提交回复
热议问题