| CodeGuru Home | VC++ / MFC / C++ | .NET / C# | Visual Basic | Newsletters | VB Forums | Developer.com |
|
|||||||
| Visual Basic .NET Microsoft Visual Basic .NET and related questions. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Re: Multiple PDF's on Server read via Stream to HTTPResponse
Hi All. I really need some help and saw this and thought you might be able to solve my issue. I have multiple PDF's that are to be merged before being displayed for opening and saving.
This is my calling routine that goes to the next code snippet to get the actual file. However it is only returning the last page in the set of for example 6 pages. Private Sub ReturnImage() Dim Exsol As ExsolRepository Dim NewBitmap As Bitmap Dim MemoryStream As System.IO.MemoryStream 'Dim Final As System.IO.MemoryStream Dim Counter As Integer Dim Name As String Dim Run As Integer Counter = 1 Run = 1 While Run <> mPageCounter + 1 ' Extract the document from Exsol Exsol = ExsolRepositoryPool.GetRepository(Me) Try MemoryStream = Exsol.GetDocumentMyAccount(mDocumentGUID, Run) ' Final.WriteByte(MemoryStream) If mPDFRetrival = False Then NewBitmap = New Bitmap(MemoryStream) End If Catch ex As Exception ex = Nothing Finally ExsolRepositoryPool.ReleaseRepository(Me, Exsol) End Try Run = Run + 1 End While Try ' Convert the image to GIF format If Not NewBitmap Is Nothing Then Response.ContentType = "image/gif" NewBitmap.RotateFlip(GetRotateConstant) NewBitmap.Save(Response.OutputStream, ImageFormat.Gif) Else Dim ImageArray() As Byte Dim Count As Integer Response.Clear() Response.ContentType = "application/pdf" Response.AddHeader("Content-Disposition", "attachment; filename=Image.pdf") Response.AddHeader("Content-Length", MemoryStream.Length.ToString()) Response.ContentType = "application/pdf" Response.BinaryWrite(MemoryStream.GetBuffer()) End If Catch ex As Exception utils.redirect("Images/Unable.gif", Me) Finally NewBitmap = Nothing End Try End Sub Calls to -> Public Function GetDocumentMyAccount(ByVal GUID As String, ByVal Run As Integer) As MemoryStream Dim NewBitmap As Bitmap Dim DataStream As MemoryStream Dim Final As MemoryStream Dim Writer As BinaryWriter Dim Buffer As Object Dim ByteBuffer() As Byte Dim FileSize As Long Dim FolderInfo As Object Dim RetryCount As Integer Dim Runner As Integer RetryCount = settings.getRPCRetryCount TryGetAgain: Try FolderInfo = mApplication.GetFolderInfo(GUID) Catch ex As Exception ' Try recovering from the failure before crashing If RetryCount > 0 Then RetryCount -= 1 GoTo TryGetAgain End If Throw ex End Try Runner = 1 Try GUID = Left(GUID, InStrRev(GUID, "}")) If LocatePage(GUID, Run) <> "" Then If OpenFileForView(Run) Then DataStream = New MemoryStream Writer = New BinaryWriter(DataStream) While Not mApplication.FileEOF Buffer = GetActualFile() ReDim ByteBuffer(UBound(Buffer) - LBound(Buffer)) Array.Copy(Buffer, ByteBuffer, UBound(Buffer) - LBound(Buffer) + 1) If ByteBuffer.Length > 0 Then Writer.Write(ByteBuffer) End If End While CloseFileForView() Else Throw New Exception("Unable to load the EXSOL file for GUID:" & GUID & ", page " & Run) End If Else Throw New Exception("Unable to find the EXSOL file for GUID:" & GUID & ", page " & Run) End If Return DataStream Finally Writer = Nothing Buffer = Nothing ByteBuffer = Nothing End Try 'End While End Function I dont want to make drastict changes and hope that a simple fix to this can be made. I am very new to this. Please help and thank you. |
|
#2
|
||||
|
||||
|
Re: Multiple PDF's on Server read via Stream to HTTPResponse
Notice the CODE TAGS! I had to format by hand!
Need to do this inside of the page loop: Code:
Try
' Convert the image to GIF format
If Not NewBitmap Is Nothing Then
Response.ContentType = "image/gif"
NewBitmap.RotateFlip(GetRotateConstant)
NewBitmap.Save(Response.OutputStream, ImageFormat.Gif)
Else
Dim ImageArray() As Byte
Dim Count As Integer
Response.Clear()
Response.ContentType = "application/pdf"
Response.AddHeader("Content-Disposition", "attachment; filename=Image.pdf")
Response.AddHeader("Content-Length", MemoryStream.Length.ToString())
Response.ContentType = "application/pdf"
Response.BinaryWrite(MemoryStream.GetBuffer())
End If
Catch ex As Exception
utils.redirect("Images/Unable.gif", Me)
Finally
NewBitmap = Nothing
End Try
End Sub
__________________
David CodeGuru Article: Bound Controls are Evil-VB6 101 Samples: VB & C# VS2008 Samples CodeGuru Reviewer 2006 Dell CSP 2006, 2007 & 2008 MVP Visual Basic If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!
|
![]() |
| Bookmarks |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|