Solved

Streaming Large PDFs to browser

Posted on 2002-03-08
2
589 Views
Last Modified: 2006-11-17
I am having problems streaming a large PDF to a browser.  When I execute the code(see below) for a smaller file, everything works fine.  However, if the file is large (~300 K) I get an Acrobat Reader error, "Error reading linearized hint data".  If I change the Acrobat Reader preference to not "Allow Fast Web View", everything works fine.  However that is not a good solution for me.  Please help me.

'ASP code
Response.Buffer = True
Response.ContentType="application/pdf"
Dim vntStream
Set oMyObject = Server.CreateObject("MyObject.BinRead")
vntStream =
  oMyObject.readBinFile("d:\sbrdev\debug\sbrquote.pdf")
Response.BinaryWrite(vntStream)
Set oMyObject = Nothing
Response.Flush
Response.End
0
Comment
Question by:sgerlach
2 Comments
 
LVL 15

Accepted Solution

by:
robbert earned 200 total points
ID: 6855087
It would probably help to split vntStream to chunks, and flush them (using MidB() and LenB()).
Anyway, the following doesn't depend on a custom COM component, and has proven its functionality for a large number of PDFs, EXEs, ZIPs and images:

--------------------------------------------------------

<%
' open the file
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objTS = objFSO.OpenTextFile("F:\webspace\resadmin\robbert\robbert.hostingcontroller.net\www\test.pdf")

' enable streaming (for IIS4; this is the default setting for IIS5)
Response.Buffer = True

' send meta information about the pdf file
Response.ContentType = "application/pdf"
Response.AddHeader "Content-disposition", "inline; filename=test.pdf"

Do While Not objTS.AtEndOfStream
    If Not Response.IsClientConnected Then
        ' prevent app from hanging if client disconnects
        Exit Sub
    End If
         
     ' read chunk
    strChunk = objTS.Read(32)
    strTmp = ""
   
    ' convert to binary charset
    For i = 1 to Len(strChunk)
        strTmp = strTmp & ChrB(Asc(Mid(strChunk, i, 1)))
    Next
   
    ' flush
    Response.BinaryWrite strTmp
    Response.Flush
Loop

' clean up
objTS.Close
Set objTS = Nothing
Set objFSO = Nothing
%>
0
 
LVL 1

Author Comment

by:sgerlach
ID: 6881183
It turned out that my file was just corrupt, but thanks for the information.  This might help me in the future.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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 …
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

706 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

18 Experts available now in Live!

Get 1:1 Help Now