473,386 Members | 1,873 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

"stream" a PDF?

I can do this in ASP, but not sure how to handle in ASP.NET:

How To Use the ADODB.Stream Object to Send Binary Files to the Browser
through ASP
http://support.microsoft.com/?kbid=276488

Do I need to use BinaryReader? Can someone give me an example?

Nov 18 '05 #1
6 4448
I'm not sure why you would need or want to do this. A browser downloads
files. A PDF document is a file. A browser can view a PDF document (if the
user is wanting a PDF document, I would have to assume that they have
Acrobat installed on their machine). So, you would load a PDF document into
a browser in the same way you would load an HTML or Text document, or any
other format that the browser recognizes: link to it, or use JavaScript to
set the location attribute of the currently loaded document to the location
of the PDF file. Or use link or JavaScript to load the PDF file into a new
browser instance. No streaming or sophisticated code needed.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living
"Tom Kaminski [MVP]" <tomk (A@T) mvps (D.O.T) org> wrote in message
news:cm*********@kcweb01.netnews.att.com...
I can do this in ASP, but not sure how to handle in ASP.NET:

How To Use the ADODB.Stream Object to Send Binary Files to the Browser
through ASP
http://support.microsoft.com/?kbid=276488

Do I need to use BinaryReader? Can someone give me an example?

Nov 18 '05 #2
Kevin Spencer wrote:
I'm not sure why you would need or want to do this. A browser
downloads files. A PDF document is a file. A browser can view a PDF
document (if the user is wanting a PDF document, I would have to
assume that they have Acrobat installed on their machine). So, you
would load a PDF document into a browser in the same way you would
load an HTML or Text document, or any other format that the browser
recognizes: link to it, or use JavaScript to set the location
attribute of the currently loaded document to the location of the PDF
file. Or use link or JavaScript to load the PDF file into a new
browser instance. No streaming or sophisticated code needed.


Linking works only if the requested file is accessible within a virtual
directory. If the PDF comes from a database, you need streaming (or you have
to store the file temporarily in a virtual directory... messy).

Anyway, streaming a PDF isn't really different from streaming any other
media type back to a web client:

1. Set the Content-Type header.
2. Set the Content-Length header, if available (*very* important for older
Acrobat plug-ins)
3. Set the Content-Disposition header for a proper client-side "Save As"
prompt.
4. Write the data back to the response stream.

Cheers,

--
Joerg Jooss
www.joergjooss.de
ne**@joergjooss.de
Nov 18 '05 #3
"Kevin Spencer" <ks******@takempis.com> wrote in message
news:uu**************@TK2MSFTNGP14.phx.gbl...
I'm not sure why you would need or want to do this.


Because I want to protect the PDFs with a custom authentication scheme and
do not want to provide a direct URL for the document. The authenticaiton is
handled within the code and thus cannot protect static files if they are
called directly.

--
Tom Kaminski IIS MVP
http://www.microsoft.com/windowsserv...y/centers/iis/
http://mvp.support.microsoft.com/
http://www.iisfaq.com/
http://www.iistoolshed.com/ - tools, scripts, and utilities for running IIS
http://www.tryiis.com
Nov 18 '05 #4
Understood.

Joerg gave you the details. If you have any further trouble, come on back.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Tom Kaminski [MVP]" <tomk (A@T) mvps (D.O.T) org> wrote in message
news:cm*********@kcweb01.netnews.att.com...
"Kevin Spencer" <ks******@takempis.com> wrote in message
news:uu**************@TK2MSFTNGP14.phx.gbl...
I'm not sure why you would need or want to do this.
Because I want to protect the PDFs with a custom authentication scheme and
do not want to provide a direct URL for the document. The authenticaiton

is handled within the code and thus cannot protect static files if they are
called directly.

--
Tom Kaminski IIS MVP
http://www.microsoft.com/windowsserv...y/centers/iis/
http://mvp.support.microsoft.com/
http://www.iisfaq.com/
http://www.iistoolshed.com/ - tools, scripts, and utilities for running IIS http://www.tryiis.com

Nov 18 '05 #5
Hi Tom,

If you can get the data into a Byte array, you can shoot it out with
BinaryWrite.

HOW TO: Read and Write a File to and from a BLOB Column by Using ADO.NET and
Visual Basic .NET

http://support.microsoft.com/default...b;en-us;316887

Here's some code I have kicking around:

Dim strFileNameToDisplay As String
Dim byteTemp As Byte()
strFileNameToDisplay = Path.GetFileName(strFileName)
Try
' Put the document bytes into the byte array
byteTemp = ' Get the PDF file here see
http://support.microsoft.com/default...b;en-us;316887
' If all went well, write the content out as a file
Response.Buffer = True
Response.Clear()
Response.ClearContent()
Response.ClearHeaders()
Response.ContentType = "application/pdf"
Response.AddHeader("Content-Disposition", _
"attachment;filename=" & strFileNameToDisplay)
Response.BinaryWrite(byteTemp)
Response.End()
strFileName = ""
Catch exc As Exception
Response.Write("Sorry, unable to retrieve the file at this
time.")
End Try

"Tom Kaminski [MVP]" <tomk (A@T) mvps (D.O.T) org> wrote in message
news:cm*********@kcweb01.netnews.att.com...
I can do this in ASP, but not sure how to handle in ASP.NET:

How To Use the ADODB.Stream Object to Send Binary Files to the Browser
through ASP
http://support.microsoft.com/?kbid=276488

Do I need to use BinaryReader? Can someone give me an example?


Nov 18 '05 #6
"Ken Cox [Microsoft MVP]" <BA************@sympatico.ca> wrote in message
news:eH*************@TK2MSFTNGP11.phx.gbl...
Hi Tom,

If you can get the data into a Byte array, you can shoot it out with
BinaryWrite.


Thanks Ken! BinaryWrite was the part I was missing (duh)!
Here's the code that works:

If File.Exists(sFile) Then

Response.Buffer = True

Response.Clear()

Response.ClearContent()

Response.ClearHeaders()

Response.ContentType = "application/pdf"

Response.AddHeader("Content-Disposition", "attachment; filename=" &
Request("tn") & ".pdf")

Dim fs As FileStream

Dim br As BinaryReader

fs = New FileStream(sFile, FileMode.Open)

br = New BinaryReader(fs)

Dim dataBytes As Byte() = br.ReadBytes(fs.Length - 1)

Response.BinaryWrite(dataBytes)

br.Close()

fs.Close()

End If

--
Tom Kaminski IIS MVP
http://www.microsoft.com/windowsserv...y/centers/iis/
http://mvp.support.microsoft.com/
http://www.iisfaq.com/
http://www.iistoolshed.com/ - tools, scripts, and utilities for running IIS
http://www.tryiis.com
Nov 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: dover | last post by:
For the code, outputfile << *p << endl; Someone suggests: Don't use endl here; it is flushing output stream every time. Use plain '\n'. What's the difference of using "endl" and "\n" above?...
11
by: Kobu | last post by:
I have a question about C's abstract "streams" (that I can't seem to FULLY understand from reading several tutorials). Streams seems to suggest that input can be treated continously if needed....
7
by: Willem van Rumpt | last post by:
Hi all, coming from an unmanaged programming background, I took my time to sort out the IDisposable and finalizer patterns. Just when I thought I had it all conceptually neatly arranged, the...
1
by: Michael Stock | last post by:
Hi all, hopefully someone can tell me how to do this for a web server in C#: We have images in a folder you can't access over the net. So everytime we need to display an image from this folder,...
2
by: CVerma | last post by:
I'm using an html input control (System.web.UI.HTMLControls.HTMLInputFile) to upload files such as msword, excel, jpg, and pdf. I have the encType property set in the form:...
19
by: VB Programmer | last post by:
If I have a VB6 and a VB.NET application, or 2 VB.NET applications what is the best way to "talk" between them? They both run on the same PC. Right now I'm just using text files to share...
5
by: StephQ | last post by:
At the moment I have a void member function (of a given class) that takes as input an obj of class type ofstream and write some debug information to it using the << operator. I would like to...
1
by: | last post by:
I've built an application that scrapes JPG images of webpages and PDF instances of those webpages automatically from an RSS feed. References to the scraped resources are persisted to our database....
4
by: =?utf-8?B?Qm9yaXMgRHXFoWVr?= | last post by:
Hello, (sorry to begin with Java in a Python list ;-) in Java, when I want to pass input to a function, I pass "InputStream", which is a base class of any input stream. In Python, I found...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.