-1

I'm using this code to read my XFA data to my vb.net application. However, I cannot figure out how to load the populatedPDFFrom to the application.

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Dim filePath As String

        filePath = "d:\waiver_testing\test_pdf\rfrprg67.pdf"

        TextBox1.Text = Export(filePath)

    End Sub

Public Shared Function Export(populatedPDFForm As System.IO.Stream) As System.IO.MemoryStream

        '  Exports XFA data from a PDF File
        '  <param name="populatedPDFForm">a readable stream of the PDF with a populated form</param>
        '  <returns>A stream containing the exported XML form data</returns>

        Dim outputStream As New System.IO.MemoryStream()
        Dim reader As New iTextSharp.text.pdf.PdfReader(populatedPDFForm)
        Dim settings As XmlWriterSettings = New XmlWriterSettings
        settings.Indent = True
        'settings.OmitXmlDeclaration = True

        Using writer = XmlWriter.Create(outputStream, settings)
            reader.AcroFields.Xfa.DatasetsNode.WriteTo(writer)
        End Using

        Return outputStream

    End Function

Error on line: textbox1.text = Export(filePath)

Error: Value type "String" cannot be converted to to "System.IO.Stream"

Can someone please throw me a bone?

Community
  • 1
  • 1
turkaffe
  • 100
  • 2
  • 12
  • possible duplicate of [Convert a String to Stream](http://stackoverflow.com/questions/351126/convert-a-string-to-stream) – Andrew Morton Feb 23 '15 at 19:35

1 Answers1

1

Well, you can not assign a MemoryStream to a string. You need to convert it first. For example to read the stream as Ascii you can use Encoding.ASCII.GetString.
Also, your Export function seems to take in a stream as a parameter and not a file path. To handle that write:

Using inStream As Stream = File.OpenRead(filePath)
  TextBox1.Text = Encoding.ASCII.GetString(Export(inStream).ToArray())
End Using
Magnus
  • 45,362
  • 8
  • 80
  • 118