2015-02-23 58 views
-1

我使用this code将我的XFA数据读取到我的vb.net应用程序。但是,我无法弄清楚如何将populatedPDFFrom加载到应用程序中。将PDF加载到VB.NET中的MemoryStream中

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 

错误就行: textbox1.text = Export(filePath)

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

可有人请把我骨头?

+0

可能重复的[将字符串转换为流](http://stackoverflow.com/questions/351126/convert-a-string-to-stream) – 2015-02-23 19:35:36

回答

1

那么,你不能指定一个MemoryStream字符串。您需要先将其转换。例如,要将流视为Ascii,您可以使用Encoding.ASCII.GetString
此外,您的Export函数似乎将流作为参数,而不是文件路径。要处理该写入:

Using inStream As Stream = File.OpenRead(filePath) 
    TextBox1.Text = Encoding.ASCII.GetString(Export(inStream).ToArray()) 
End Using