【问题标题】:MVC - Generating multiple PDFsMVC - 生成多个 PDF
【发布时间】:2014-12-29 05:43:54
【问题描述】:

我正在使用以下代码生成PDF 文件。

它运行良好,但现在我想同时生成4 PDF's

我尝试再次启动 Document 并重复生成第二个 PDF 报告的整个代码,但它只生成 1 个 PDF。

            var document = new Document(PageSize.A4, 50, 50, 25, 25);

            // Create a new PdfWrite object, writing the output to a MemoryStream
            var output = new MemoryStream();
            var writer = PdfWriter.GetInstance(document, output);

            // Open the Document for writing
            document.Open();

            string contents = System.IO.File.ReadAllText(Server.MapPath("~/Reports/Original.html"));

            var parsedHtmlElements = HTMLWorker.ParseToList(new StringReader(contents), null);
            foreach (var htmlElement in parsedHtmlElements)
                     document.Add(htmlElement as IElement);    

           document.Close();

           Response.ContentType = "application/pdf";
           Response.AddHeader("Content-Disposition", string.Format("attachment;filename=Receipt-{0}.pdf", "Report"));
           Response.BinaryWrite(output.ToArray());

           return View();

如何生成多个PDF?

【问题讨论】:

    标签: c# asp.net-mvc pdf document


    【解决方案1】:

    您正在输出字节作为响应,因此您永远无法在一个响应中生成 2 个不同的文件。每个请求只有一个响应。 如果您希望用户同时下载 2 个不同的 PDF,您可以使用视图中的 javascript 调用控制器。

    【讨论】:

    • 我会试一试的..!
    • 请给我正确答案!我对积分绝望了哈哈
    猜你喜欢
    • 1970-01-01
    • 2016-10-14
    • 2015-11-22
    • 1970-01-01
    • 2013-01-19
    • 2015-03-11
    • 2018-05-12
    • 2018-08-08
    • 2010-12-18
    相关资源
    最近更新 更多