Solved

binarywrite with PDF problem

Posted on 2001-06-05
2
773 Views
Last Modified: 2007-11-27
I am trying to binarywrite a PDF file to the browser.  No matter what I try, I just get the binary data in the browser, instead of acrobat opening.  Please look at this code and tell me if you can find any problems.  Thanks..

---- ASP
     Set objBinFile = Server.CreateObject("ASPBinFile.clsASPBinFile")
     mFile = rsinvoice("filename")
     mStream = objBinFile.BinFileRead(mFile)
     response.buffer=true
'      Response.CacheControl = "public"
'     response.expires = 0
     Response.contenttype = "application/pdf"
     Response.AddHeader "Content-Disposition", "inline;filename=invoice.pdf"
'     Response.Addheader "Content-Length", LenB(mstream)
     Response.binarywrite mstream
     response.end()
     response.flush
     Set objBinFile = Nothing
else
     response.write "DOH!"
end if

---- objBinFile.BinFileRead()
Option Explicit


Function BinFileRead(ByVal inFileSpec As String) As Variant
     On Error GoTo errHandler
     Dim mHandle
     Dim lngFileLen As Long
     Dim arrData() As Byte
       
     mHandle = FreeFile
     Open inFileSpec For Binary Access Read As #mHandle

     lngFileLen = FileLen(inFileSpec)
     ReDim arrData(lngFileLen)

     Get #mHandle, , arrData
     Close #mHandle
       
     BinFileRead = arrData
     Exit Function

errHandler:
End Function
0
Comment
Question by:tranqy
2 Comments
 

Accepted Solution

by:
Chesty earned 200 total points
ID: 6157483
Are you including the <html> and <head> tags like you would for an ordinary web page? Don't. It makes the browser expect a web page.

If your asp page is called "invoice.asp" it must be..

<%
Set ObjBinFile....
.
.
.
Set ObjBinFile=Nothing
Response.End
%>

You can't put response.write statements in either because you have told the browser it is "application/pdf". Link to "invoice.asp" as you would any other file for download and it should work.
0
 

Author Comment

by:tranqy
ID: 6159274
I worked with this page forever, and all I had to do was pull out the html tags.  ARGH.  Thank you very much for your insight.  Your answer fixed my problem!
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now