0

我设计了 .aspx 页面,我正在尝试为我的页面生成 PDF,但它在下面显示“adobe reader 无法打开,因为文件已损坏”我粘贴了 generatePDF 的代码供您参考。请帮助我

    Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)
     ''// Verifies that the control is rendered 
    End Sub

    Private Sub btnPdf_Click(ByVal sender As System.Object, ByVal e As   System.EventArgs) Handles btnPdf.Click       
     Dim Response As System.Web.HttpResponse = System.Web.HttpContext.Current.Response
    Try


        Dim parag As Paragraph = Nothing
        Dim pdfPath As String = Server.MapPath("") & "\test.pdf"
        If File.Exists(pdfPath) Then
            File.Delete(pdfPath)
        End If  
        Response.Clear()
        Response.Buffer = True
        Response.AddHeader("content-disposition", "attachment;filename=test.pdf")
        Response.ContentEncoding = System.Text.Encoding.UTF7
        Response.ContentType = "application/pdf"
        Dim oStringWriter As New System.IO.StringWriter
        Dim oHtmlTextWriter As New System.Web.UI.HtmlTextWriter(oStringWriter)
        home.RenderControl(oHtmlTextWriter)
        Response.Output.Write(oStringWriter.ToString())
        Response.Flush()
        Response.End()
     Catch ex As Exception

    End Try
End Sub
4

0 回答 0