【发布时间】:2018-08-08 19:26:53
【问题描述】:
控制器:
<HttpGet>
Function downloadpdf() As FileContentResult
Dim data As MyData = Me.Getdata()
Dim sb As StringBuilder = New StringBuilder()
If data IsNot Nothing Then
If data.HasItems Then
sb.AppendLine()
sb.AppendLine("ID,Description)
For Each item In data.Items
sb.AppendLine(String.Format("{0},{1}", item.Id, item.Description))
Next
End If
End If
Dim bytes as Byte() = New UTF8Encoding().GetBytes(sb.ToString())
Response.Clear()
Response.AddHeader("Content-Disposition", "inline; filename=mypdf.pdf")
Response.AddHeader("Content-Type", "application/pdf")
Response.ClearHeaders()
Response.AddHeader("Content-Length", bytes.Length.ToString())
Return File(bytes, "application/pdf", "mypdf.pdf")
End Function
查看:
<a href="@Url.Action("downloadpdf", "home")">PDF</a>
点击链接时,提示下载文件,然后显示如下:
Adobe Acrobat Reader 无法打开“mypdf.pdf”,因为它不是受支持的文件类型或文件已损坏(例如,它作为电子邮件附件发送且未正确解码)。
而且 pdf 没有打开。 有什么建议或任何其他方式吗?
干杯
【问题讨论】:
标签: asp.net-mvc vb.net pdf