I believe there is a bug with the OpenDocument method. I am storing files in a database and then can read the file into an array of bytes. I am able to save the file to a file in a temp folder and it reads fine with OpenDocument.
However instead of wasting resourses writing/reading a file, I am trying to read the array of bytes directly with OpenDocument. This works perfectly fine on all documents EXCEPT for PDFs. For the PDF’s it knows the number of pages but only is able to display the first page and the remaining pages state “no preview available”. image.png (86.5 KB)
I’m including the code (sorry it’s in VB). The section that is commented out is the part that writes to a file, which works. The last line where it opens the document is the part that only displays the first page.
Public Sub GetFile()
Dim cnn As SqlConnection
Dim strSQL As String
Dim cmdSQL As SqlCommand
Dim dtrRS As SqlDataReader
Dim FileName As String = ""
cnn = New SqlConnection(Session("cnnCUS"))
Dim data As Byte() = Nothing
strSQL = "select FileName, FileData, FileType from FileMgr where FileID='" & ViewState("FileID") & "'"
cmdSQL = New SqlCommand(strSQL, cnn)
cnn.Open()
dtrRS = cmdSQL.ExecuteReader
If dtrRS.Read = True Then
data = dtrRS("FileData")
FileName = dtrRS("FileName")
End If
dtrRS.Close()
cnn.Close()
'get the file extension
Dim periodPos As Integer = InStrRev(FileName, ".",, CompareMethod.Text)
Dim ext As String = Right(FileName, Len(FileName) - periodPos)
'Dim strUploadPath As String = "~/Temp/"
'File.WriteAllBytes(Server.MapPath(strUploadPath) + FileName, data)
'ctlDoc.OpenDocument(Server.MapPath(strUploadPath) + FileName)
'If System.IO.File.Exists(Server.MapPath(strUploadPath) + FileName) Then System.IO.File.Delete(Server.MapPath(strUploadPath) + FileName)
ctlDoc.OpenDocument(data, ext)
End Sub