Solved

Streaming Large PDFs to browser

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
EOF BOF error classic asp 8 48
Adding Datediff to staistics page 2 56
Attaching a file to SMTP in Classic ASP 1 41
Passing Parameter to Stored Procedure 4 24
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/…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

803 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