Convert byte array to PDF without saving as a file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • doubler
    New Member
    • Nov 2012
    • 4

    Convert byte array to PDF without saving as a file

    I have a Windows app created in VS2012. I'm calling a web service that is returning a pdf as a byte array. I want to convert the array back to a pdf and display it to the user without having to save it as a file first.
  • wholetthedogout
    New Member
    • Nov 2012
    • 6

    #2
    Can you please put in the code you tried so far.

    Thank you.

    Comment

    • doubler
      New Member
      • Nov 2012
      • 4

      #3
      That's the problem. I haven't found many examples for a Windows form that I could test with. I did try this, but I'm missing whatever makes the document display.

      Code:
       Dim arrPage() As Byte = Nothing
       arrPage = pdfWS.RetrieveDocument(docID, docRefID)
       
       Dim ms As MemoryStream = New MemoryStream
       ms.Write(arrPage, 0, arrPage.Length)

      Comment

      • !NoItAll
        Contributor
        • May 2006
        • 297

        #4
        Without adding a reference to a PDF reader of some sort then you are pretty much stuck with writing it to a file and then calling whatever PDF reader is installed on the machine.
        The following code will write your byte array to a pdf document, then load it in the currently installed pdf reader (adobe reader).

        Code:
        My.Computer.FileSystem.WriteAllBytes("MyPDF.pdf", MyByteArray, False)
        System.Diagnostics.Process.Start("MyPDF.pdf")
        Otherwise you would need a PDF control (preferably a native .net one) with it's own methods for accepting a byte array directly from and into its own buffers.
        That might be expensive. One like the following might work:



        But you need $299.00

        Comment

        Working...