CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • Installing SQL Server 2008
  • Writing UDFs for Firebird Embedded SQL Server
  • [Updated] Shutdown Manager
  • Building Windows Azure Cloud Service Applications with Azure Storage and the Azure SDK

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > Visual Basic Programming > Visual Basic .NET
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    Visual Basic .NET Microsoft Visual Basic .NET and related questions.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1    
    Old November 3rd, 2009, 01:30 PM
    TCPDWPZN TCPDWPZN is offline
    Junior Member
     
    Join Date: Nov 2009
    Posts: 2
    TCPDWPZN is an unknown quantity at this point (<10)
    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.
    Reply With Quote
      #2    
    Old November 4th, 2009, 12:02 AM
    dglienna's Avatar
    dglienna dglienna is offline
    ex MVP - Visual Basic
    Power Poster
     
    Join Date: Jan 2006
    Location: Chicago, IL
    Posts: 9,895
    dglienna has a brilliant future (2000+)dglienna has a brilliant future (2000+)dglienna has a brilliant future (2000+)dglienna has a brilliant future (2000+)dglienna has a brilliant future (2000+)dglienna has a brilliant future (2000+)dglienna has a brilliant future (2000+)dglienna has a brilliant future (2000+)dglienna has a brilliant future (2000+)dglienna has a brilliant future (2000+)dglienna has a brilliant future (2000+)
    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!
    Reply With Quote
    Reply

    Bookmarks
    Go Back   CodeGuru Forums > Visual Basic Programming > Visual Basic .NET


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 02:10 AM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
    Copyright WebMediaBrands Inc. 2002-2009