-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?

1

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.