Solved

Streaming Large PDFs to browser

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

830 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