我正在尝试在表格顶部的屏幕上设置一个按钮,单击该按钮会下载包含用户看到的表格内容的 pdf。
这就是我创建 PDF 的方式以及 Action 方法的样子......
public ActionResult DownloadPdf(string content)
{
MemoryStream outputStream = new MemoryStream();
MemoryStream workStream = new MemoryStream();
Document document = new Document();
PdfWriter.GetInstance(document, workStream);
document.Open();
document.Add(new Paragraph(content));
document.Close();
byte[] byteInfo = workStream.ToArray();
outputStream.Write(byteInfo, 0, byteInfo.Length);
outputStream.Position = 0;
//Response.AddHeader("Content-Disposition", "attachment; filename=test.pdf");
//return File(byteInfo, "application/pdf", "test.pdf");
return File(outputStream, "application/pdf", "test.pdf");
}
这是我试图打印的表格...
<table class="donationTable statementTable">
<tr>
<th>Month</th> <th>Fees</th>
</tr>
<tr>
<td>
Jan
</td>
<td>
$5
</td>
</tr>
</table>
<a href = "@Url.Action("DownloadPdf", "Home", new { content = "" })">Download</a>