Solved

Streaming Large PDFs to browser

Posted on 2002-03-08
2
600 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Get hold of longitude and latitude in iframe string 11 61
Connection to multiple databases 13 45
Use Mid in Html 6 35
ms sql string field to asp variable as number 5 31
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

739 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