我正在嘗試的是在桌面上的一個屏幕上有一個按鈕,當點擊該按鈕時,下載帶有用戶看到的表格內容的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