D
DBLWizard
Howdy,
I am trying to write code in Visual Basic 6.0 being called from an asp
page. I am trying to write code that allows me to "stream" large size
PDF's. By large size I mean files that are 50MB to 100MB. The reason
to "stream" this is so that the customer does not sit there waiting
for for the PDF to display and thinking there is a problem becuase it
just displays a blank screen until the complete PDF is downloaded.
This code works fine if I do a single BinaryWrite but that again does
not solve the problem. With the code below the file comes down but it
is corrupted. Each page only partially displays. I have played with
it and I can tell that the part of the page that displays is related
to the BUFFER_SIZE. Does anybody see what is wrong with this code?
Thanks
dbl
Private Sub PXCPDF_WriteBuffer(lpPDF_A As Long, sFileNameA As String)
Const BUFFER_SIZE = 20480
Dim lRC As Long
Dim lStreamLength As Long
Set mobjStream = olelib.CreateStreamOnHGlobal(0, True)
lRC = PXC_WriteDocumentToIStream(lpPDF_A, mobjStream)
If (IS_DS_FAILED(lRC)) Then
Exit Sub
End If
Call mobjStream.Stat(mobjStreamStat)
lStreamLength = Currency2Long(mobjStreamStat.cbSize)
Dim lBytesToRead As Long
Dim curBufferPtr As Currency
Dim curReturn As Currency
Dim objResponse As Response
Set objResponse = mobjContext("Response")
lBytesToRead = BUFFER_SIZE
ReDim mabtBuffer(lBytesToRead)
curBufferPtr = 0
objResponse.Buffer = True
objResponse.ContentType = "application/pdf"
objResponse.AddHeader "Content-disposition", _
"inline; filename=" + sFileNameA + "_doc.pdf"
While curBufferPtr < mobjStreamStat.cbSize
If curBufferPtr + Long2Currency(lBytesToRead) >
mobjStreamStat.cbSize Then
lBytesToRead = Currency2Long(mobjStreamStat.cbSize -
curBufferPtr)
End If
ReDim mabtBuffer(lBytesToRead)
curReturn = mobjStream.Seek(curBufferPtr,
olelib.STREAM_SEEK_SET)
lRC = mobjStream.Read(mabtBuffer(0), lBytesToRead)
curBufferPtr = curBufferPtr + Long2Currency(lBytesToRead)
objResponse.BinaryWrite (mabtBuffer)
objResponse.Flush
Wend
objResponse.End
Set objResponse = Nothing
Set mobjStream = Nothing
End Sub
I am trying to write code in Visual Basic 6.0 being called from an asp
page. I am trying to write code that allows me to "stream" large size
PDF's. By large size I mean files that are 50MB to 100MB. The reason
to "stream" this is so that the customer does not sit there waiting
for for the PDF to display and thinking there is a problem becuase it
just displays a blank screen until the complete PDF is downloaded.
This code works fine if I do a single BinaryWrite but that again does
not solve the problem. With the code below the file comes down but it
is corrupted. Each page only partially displays. I have played with
it and I can tell that the part of the page that displays is related
to the BUFFER_SIZE. Does anybody see what is wrong with this code?
Thanks
dbl
Private Sub PXCPDF_WriteBuffer(lpPDF_A As Long, sFileNameA As String)
Const BUFFER_SIZE = 20480
Dim lRC As Long
Dim lStreamLength As Long
Set mobjStream = olelib.CreateStreamOnHGlobal(0, True)
lRC = PXC_WriteDocumentToIStream(lpPDF_A, mobjStream)
If (IS_DS_FAILED(lRC)) Then
Exit Sub
End If
Call mobjStream.Stat(mobjStreamStat)
lStreamLength = Currency2Long(mobjStreamStat.cbSize)
Dim lBytesToRead As Long
Dim curBufferPtr As Currency
Dim curReturn As Currency
Dim objResponse As Response
Set objResponse = mobjContext("Response")
lBytesToRead = BUFFER_SIZE
ReDim mabtBuffer(lBytesToRead)
curBufferPtr = 0
objResponse.Buffer = True
objResponse.ContentType = "application/pdf"
objResponse.AddHeader "Content-disposition", _
"inline; filename=" + sFileNameA + "_doc.pdf"
While curBufferPtr < mobjStreamStat.cbSize
If curBufferPtr + Long2Currency(lBytesToRead) >
mobjStreamStat.cbSize Then
lBytesToRead = Currency2Long(mobjStreamStat.cbSize -
curBufferPtr)
End If
ReDim mabtBuffer(lBytesToRead)
curReturn = mobjStream.Seek(curBufferPtr,
olelib.STREAM_SEEK_SET)
lRC = mobjStream.Read(mabtBuffer(0), lBytesToRead)
curBufferPtr = curBufferPtr + Long2Currency(lBytesToRead)
objResponse.BinaryWrite (mabtBuffer)
objResponse.Flush
Wend
objResponse.End
Set objResponse = Nothing
Set mobjStream = Nothing
End Sub