Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7503963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:24:26+00:00 2026-05-29T21:24:26+00:00

My app receives a PDF as a base64, zLib deflated string in an xml

  • 0

My app receives a PDF as a base64, zLib deflated string in an xml file. At least that’s the format I’m told it is in. It gets stored in a database, then I need to recreate the PDF from that string. I created a test app to figure it out. The function below takes the string and is supposed to return it in a decoded, inflated format which I believe I’ll be able to use to rebuild the original PDF (I’m not there yet).

I’ve done lots of research and found a few different libraries and ways to do this as well as received a java program from the developer who is sending me the PDF to use as an example. However I can not get the string to a usable format. Using the ManagedZLib.dll and the function below seems to get me the closest. As far as I can tell from debugging, everything works until I try to decompress:

zStream.Read(decompressedBytes, 0, decodedBytes.Length - 1)

This produces a “zLib error: -3”. The only info I can find on that error is it is a ‘data error’. There is very little other information on the web about it.

Any help getting past this error, or thoughts on a different/better approach to accomplish my end goal is greatly appreciated.

Public Function DecompressString4(ByVal origString As String) As String

    Dim returnString = Nothing
    ' get the base64 content into String
    ManagedZLib.ManagedZLib.Initialize()

    '// parse the string into a byte array
    Dim b64bytes() As Byte = System.Text.Encoding.UTF8.GetBytes(origString)
    Dim decodedBytes() As Byte = Nothing

    'decode the byte array into another byte array, but this time of Base 64.
    Using ms As New MemoryStream(b64bytes)
        Using zStream As New ManagedZLib.Base64Stream(ms, Base64Options.Decode)
            ReDim decodedBytes(b64bytes.Length)
            zStream.Read(decodedBytes, 0, b64bytes.Length)
        End Using
    End Using

    decmpStrTxtBox.Text = Convert.ToString(decodedBytes)

    Dim decompressedBytes() As Byte = Nothing

    ' inflate the base64 array
    Using ms2 As New MemoryStream(decodedBytes)
        Using zStream As New ManagedZLib.CompressionStream(ms2, CompressionOptions.Decompress)
            'ReDim decompressedBytes(origString.Length)
            ReDim decompressedBytes(decodedBytes.Length)
            zStream.Read(decompressedBytes, 0, decodedBytes.Length - 1)
        End Using
    End Using

    'write output to a stream
    returnString = Convert.ToString(decompressedBytes)
    ManagedZLib.ManagedZLib.Terminate()

    Return returnString

End Function
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T21:24:28+00:00Added an answer on May 29, 2026 at 9:24 pm

    Apparently I was making it too complicated. Here is the final solution for taking a base64 deflated string, decoding it, then inflating it and outputting a PDF from it. It could easily be tweaked to return the resulting string if needed. I ended up having much better results by not including any libraries (that were supposed to make it easier 🙂 ). I didn’t actually find an answer to the error I was receiving and only assume that library wasn’t designed for my purposes. Using the built in .net classes did the trick much better (Convert.FromBase64String and System.IO.Compression.DeflateStream).

    I hope this helps someone in the future as I couldn’t find an example of this anywhere.

    Imports System.IO
    Imports System.IO.Compression
    Imports System.Text
    
        Public Sub DecompressString(ByVal origString As String)
    
        Dim decodedDeflatedBytes() As Byte = Nothing
        Dim decodedInflatedBytes() As Byte = Nothing
    
        'parse the string into a decoded byte array
        decodedDeflatedBytes = Convert.FromBase64String(origString)
    
        'once around the block to get the length of the buffer we'll need
        Dim decompressedBufferLength As Integer = 0
        Using ms1 As New MemoryStream(decodedDeflatedBytes)
            Using dStream1 As System.IO.Compression.DeflateStream = New System.IO.Compression.DeflateStream(ms1, Compression.CompressionMode.Decompress)
                While dStream1.ReadByte <> -1  ' -1 indicates nothing left to read
                    decompressedBufferLength += 1
                End While
            End Using
        End Using
    
        'a second time around the block to do the actual inflation now that we have the length
        Using ms2 As New MemoryStream(decodedDeflatedBytes)
            Using dStream2 As System.IO.Compression.DeflateStream = New System.IO.Compression.DeflateStream(ms2, Compression.CompressionMode.Decompress)
                ReDim decodedInflatedBytes(decompressedBufferLength - 1) '11711
                dStream2.Read(decodedInflatedBytes, 0, decompressedBufferLength) '11712
            End Using
        End Using
    
        'output the PDF with a 'save as' prompt
        Response.ClearContent()
        Response.ClearHeaders()
        Response.Clear()
        Response.ContentType = "Application/pdf"
        Response.AddHeader("Content-Length", decodedInflatedBytes.Length.ToString)
        Response.AddHeader("content-disposition", "attachment;filename=YourReport.pdf")
        Response.BinaryWrite(decodedInflatedBytes)
        Response.End()
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to debug an issue that only occurs when my iPhone app receives
I'm building an SMS call and response system in a new app that receives
I have a little logging app (written in wxPython) that receives data from a
I have an app that receives push notifications from C2DM server with a BroadcastReceiver.
My WPF App receives a stream of messages from a backend service that I
I'm developing an Android app that receives a byte array that is a GSM
When my iPhone app receives a memory warning the views of UIViewControllers that are
At the moment, my app receives KML file from server and displays all the
I have a monitoring app that receives processing updates from other applications via WCF.
Our app receives a list of records that are to replace an existing set

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.