Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display a binary PDF file from a database in ASP 3

Status
Not open for further replies.

towser

Programmer
Feb 19, 2001
29
GB
I have an ASP application that calls a VB component, requesting a PDF from a back end DOC1 application. The PDF is passed back to the ASP as binary within a variable of type VARIANT.

How can I then display this binary data as a PDF document?

I've used the response object to do this before, but that was always using a physical PDF that exists on a server somewhere. This time however it's just in memory in a variable.

Thanks folks.
 
It is a byte array stored in a variant.

Does this not work?
Response.ContentType = "application/octet-stream"
Response.AddHeader "Content-Disposition","attachment;filename=MyDoc.pdf"
Response.BinaryWrite MyByteArray



 
Thanks Sheco.

All I know is when I response.write the variable suposedly containing the PDF it just displays a load of ????% etc.

I will try your code and get back to you.
 
Well a byte can hold a number from 0 to 255 but regular ASCII text only occupies the space below 127 so you've got non-character byte data being evaluated as text.

Hmm.. thats not so clear, thy this from MSDN:
-------------------------------
The BinaryWrite method writes the specified information to the current HTTP output without any character conversion. This method is useful for writing nonstring information, such as binary data required by a custom application.


Parameters
The data to write to the HTTP output. This parameter is of type VT_ARRAY | VT_UI1, which is a variant array of unsigned one-byte characters.

Return Values
This method has no return values.


 
Sheco that works a treat mate, you are a star.

The only thing that I know my users will probably complain about is the windows file download alert prompt !! But I bet you can't control that in the response object settings.

Cheers Again.
 
Even though that works, I'd rather the PDF open within IE rather than fully opening Acrobat, is that possible ?

Thanks in advance
 
Probably...

The first thing I'd try would be changing the ContentType to "application/pdf
 
Towser,

If you add the following to what you are outputting:

Code:
Response.AddHeader("Content-Disposition", "inline; filename=filename.PDF");

it should open up in the browser. As well, if they try to save the PDF they will get a meaningful name (you can set that to whatever you want).

Also, I always set the ContentEncoding to Unicode (although to be fair, this is in ASP.NET) using

Code:
Response.ContentEncoding = System.Text.Encoding.Unicode;

Hope this is useful.

Chaz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top