Some scanners mail the scanned pdf file as an application octet-stream with pdf extension these are indeed pdf files currently they are not. When you try to download an unknown type of file from the Web or in an email attachment, your computer may identify it as an 'octet-stream' file. These OCTET-STREAM files may be opened by renaming the extension of the attached file to a specific file extension, and then by using an application with support for opening such files. For example, an.octet-stream file may be renamed to a.txt file (if it is indeed a.txt file), and Notepad may then be used to open the file. This means the user.
- Application Octet Stream File
- Binary Octet Stream
- Convert Octet Stream To Word
- Convert Application/octet-stream To Pdf C#
I have a byteArray which is a docx. I'm trying to convert it to pdf and add it to the Response object so the user can download it or open it.
I've tried this which the pdf is corrupted
'docArray is the byte file from the db
Try
Dim doc As Spire.Doc.Document = New Spire.Doc.Document()
Dim oFileStream As System.IO.FileStream
Application Octet Stream File
oFileStream = New System.IO.FileStream(strTempName, System.IO.FileMode.Create)
Binary Octet Stream
'Write file to streamoFileStream.Write(docArray, 0, docArray.Length - 1)
'Add docx to stream
doc.LoadFromStream(oFileStream, Spire.Doc.FileFormat.Docx)
'Covert docx to PDF
doc.SaveToStream(oFileStream, Spire.Doc.FileFormat.PDF)
Dim streamLength As Integer = Convert.ToInt32(oFileStream.Length)
Dim fileData As Byte() = New Byte(streamLength) {}
' Read the file into a byte array
oFileStream.Read(fileData, 0, streamLength)
oFileStream.Close()
strTempName = strTempName.Substring(0, strTempName.IndexOf('.'))
Context.Response.Clear()
Convert Octet Stream To Word
Context.Response.AddHeader('Content-Disposition', 'inline;attachment; filename='' & strTempName & '.pdf' & '')Context.Response.AddHeader('Content-Length', fileData.Length.ToString())
Context.Response.ContentType = 'application/octet-stream'
Context.Response.BinaryWrite(fileData)
Context.Response.Flush()
Catch ex As Exception
Context.Response.ContentType = 'text/plain'
Context.Response.Write(ex.Message)
Finally
Context.Response.[End]()
End Try
And this gives me errors..
Convert Application/octet-stream To Pdf C#
Using ms As Stream = New MemoryStream(docArray, True)
ms.Write(docArray, 0, docArray.Length)
doc.SaveToStream(ms, Spire.Doc.FileFormat.PDF)
Please help.
Thanks,
J Torres