在网络浏览器中显示PDF时出现错误"Adob​​e Reader无法打开...". [英] error displaying apdf in web browser "Adobe reader could not open ...."

查看:805
本文介绍了在网络浏览器中显示PDF时出现错误"Adob​​e Reader无法打开...".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将pdf保存到sql server 2008,并以此将pdf删除

该代码可在开发机上使用

I save a pdf to sql server 2008 and to this diplay the pdf

this code works on development machine

Public Sub viewBatchDoc()
      Dim id = Request.QueryString("id")
      Dim row() As DataRow
      Dim dtBatch As DsBatch.BatchDataTable
      dtBatch = Session("dt")
      row = dtBatch.Select("BatchNo =" & id)
      Response.Buffer = True
      Response.ContentType = "Application/PDF"
      Response.BinaryWrite(row(0).Item("fileBatch"))



但是在生产服务器上,我收到错误消息,因为"Adob​​e Reader无法打开"sample.pdf",因为它不是受支持的文件类型,或者因为文件已损坏



But on the production server I am getting the error as "Adobe reader could not open "sample.pdf" because it is either not a supported file type or because the file has been damaged

推荐答案

这是流式传输数据的另一种方式

Here is another way of streaming your data

Dim stream As Stream = Nothing
Try
    If Not [String].IsNullOrEmpty(fileName) AndAlso Not [String].IsNullOrEmpty(file) Then
        ' Open the file into a stream.
        stream = New FileStream(file, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read)
        ' Total bytes to read:
        Dim bytesToRead As Long = stream.Length
        Response.ContentType = "Application/pdf"
        Response.AddHeader("Content-Disposition", "attachment; filename=" & fileName)
        ' Read the bytes from the stream in small portions.
        While bytesToRead > 0
            ' Make sure the client is still connected.
            If Response.IsClientConnected Then
                ' Read the data into the buffer and write into the
                ' output stream.
                Dim buffer As Byte() = New [Byte](Int16.MaxValue - 1) {}
                Dim length As Integer = stream.Read(buffer, 0, Int16.MaxValue)
                Response.OutputStream.Write(buffer, 0, length)
                Response.Flush()
                ' We have already read some bytes.. need to read
                ' only the remaining.
                bytesToRead = bytesToRead - length
            Else
                ' Get out of the loop, if user is not connected anymore..
                bytesToRead = -1
            End If
        End While
    End If
Catch ex As Exception
        ' An error occurred..
    Response.Write(ex.Message)
Finally
    If stream IsNot Nothing Then
        stream.Close()
    End If
End Try


这篇关于在网络浏览器中显示PDF时出现错误"Adob​​e Reader无法打开...".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆