在尝试制作PDF响应时被困住了

时间:2015-12-22 16:29:57

标签: c# asp.net pdf response

我正在尝试制作PDF报告,但我甚至无法使Hello World示例正常工作。这就是我想要做的事情:

    protected void btnPrint_Click(object sender, EventArgs e)
    {
        using (var ms = new MemoryStream())
        {
            Response.Clear();
            Response.ContentType = "application/pdf";
            Response.AddHeader("Content-Disposition","attachment;filename=abc.pdf");
            byte[] byteStream = createPDF();
            Response.BinaryWrite(byteStream);
            Response.Flush();
            Response.End();
        }

    }

    private byte[] createPDF()
    {
        Document doc = new Document(PageSize.A4, 50, 50, 50, 50);

        using (MemoryStream output = new MemoryStream())
        {
            PdfWriter wri = PdfWriter.GetInstance(doc, output);
            doc.Open();
            Paragraph paragraph = new Paragraph("Hello World.");
            doc.Add(paragraph);
            doc.Close();
            return output.ToArray();
        }
    }

当我做Response.End()时,我没有得到回应。我不知道如何使用浏览器开发人员工具调试此请求。有人可以帮助我或给我任何想法吗?

0 个答案:

没有答案