【问题标题】:ASP.Net WebAPI Return value for PDF Form SubmitPDF 表单提交的 ASP.Net WebAPI 返回值
【发布时间】:2014-08-06 23:35:24
【问题描述】:

如何让我的 Asp.net webapi 返回正确的 pdf 表单提交响应?

【问题讨论】:

    标签: asp.net pdf asp.net-web-api


    【解决方案1】:

    要将响应保留在 pdf 应用程序中,您必须返回 FDF 格式的文件。

    让这个工作的关键是你不能只返回一个字符串。您必须先将其编码为内存流,并且标头必须设置为application/vnd.fdf

    示例代码如下:

    Public Function PostValue(<FromBody()> ByVal value As MyPDFFieldsObject) As HttpResponseMessage
            Dim fdfmessage As String = "%FDF-1.2" & vbCrLf & _
                    "1 0 obj <<" & vbCrLf & _
                    "/FDF <<" & vbCrLf & _
                    "/Status (Submitted Successfully!)" & vbCrLf & _
                    ">>" & vbCrLf & _
                    ">>" & vbCrLf & _
                    "endobj" & vbCrLf & _
                    "trailer" & vbCrLf & _
                    "<</Root 1 0 R>>" & vbCrLf & _
                    "%%EOF"
            Dim result As HttpResponseMessage = New HttpResponseMessage(HttpStatusCode.OK)
            Dim stream As New MemoryStream(Encoding.UTF8.GetBytes(fdfmessage))
            stream.Position = 0
            result.Content = New StreamContent(stream)
            result.Content.Headers.ContentType = New MediaTypeHeaderValue("application/vnd.fdf")
            Return result
        End Function
    

    【讨论】:

      猜你喜欢
      • 2019-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-23
      • 1970-01-01
      • 2011-01-29
      相关资源
      最近更新 更多