ASP.NET convert and download pdf using ClosedXML and Spire.XLS
<p>I use Web Forms. I try to convert ClosedXML excel workbook to pdf using Spire.XLS and download it by a client.
Here is my code:</p>

<pre><code>protected void btnExport_OnClick(object sender, EventArgs e)
    {
        var excel = Reporting.GenerateExcel(); //custom, return XLWorkbook object
        string myName = Server.UrlEncode(121 + "_" + DateTime.Now.ToShortDateString() + ".xlsx");
        MemoryStream stream = GetStream(excel);
        MemoryStream stream1 = new MemoryStream();


        Workbook book = new Workbook();
        book.LoadFromStream(stream);
        book.SaveToStream(stream1, FileFormat.PDF);

        Response.Clear();
        Response.Buffer = true;
        Response.AddHeader("content-disposition", "attachment; filename=" + myName);
        Response.ContentType = "application/pdf";
        Response.BinaryWrite(stream1.ToArray());
        Response.End();
    }

    public MemoryStream GetStream(XLWorkbook excelWorkbook)
    {
        MemoryStream fs = new MemoryStream();
        excelWorkbook.SaveAs(fs);
        fs.Position = 0;
        return fs;
    }
</code></pre>

<p>It seems like I receive not correct pdf. Thanks</p>