我正在尝试的是在桌面上的一个屏幕上有一个按钮,当点击该按钮时,下载带有用户看到的表格内容的PDF。如何通过mvc动作发送html表格?
这是我如何创建PDF,什么动作方法看起来像......
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>
该表格是如何生成的?你正在使用一些服务器端控制?你打算使用什么库来创建一个PDF文件,因为我们都知道.NET没有内置的这种能力。 – 2012-07-19 08:31:38
表格是硬编码(这是您向我们展示的内容)还是包含动态数据?此外,我已将'itextsharp'标记添加到您的问题中,显然这是您用于生成PDF的框架。 – 2012-07-19 08:33:30
几个PDF生成器库可以从URL创建PDF。 – 2012-07-19 08:33:54