【发布时间】: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