Solved

Streaming Large PDFs to browser

Posted on 2002-03-08
2
590 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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 demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

930 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

14 Experts available now in Live!

Get 1:1 Help Now