Preview PDF in InfoPath Form? - InfoPath Dev
in

InfoPath Dev

Preview PDF in InfoPath Form?

Last post 09-03-2010 02:17 PM by davemor. 0 replies.
Page 1 of 1 (1 items)
Sort Posts: Previous Next
  • 09-03-2010 02:17 PM

    • davemor
    • Not Ranked
    • Joined on 06-08-2010
    • Montana
    • Posts 5

    Preview PDF in InfoPath Form?

    I have a secondary Web Services data source in my form. One field contains PDF images. When I search for and return a record, I wish to display (preview) the PDF in the form. I tried adding the Adobe PDF Reader ActiveX but don't know how to pass the PDF binary data from the web service to it.

    I can get the record, I can return all the other fields correctly. I can even write out the PDF binary to a file. What I can't figure out is how to display the PDF as an image in the form. I want the users to be able to see the PDF image inline with the metadata for that PDF.

    Am I going down the wrong path? Is there an easier way?

    **********************************************************************************************************************************************************************

    Dim xpathFC As String = "/dfs:myFields/dfs:dataFields/tns:FetchManyResponse/docs/fileContent"
    Dim nav1 As XPathNavigator = Me.DataSources("fetchMany").CreateNavigator()    'Me.DataSources("FetchManyResponse/docs/fileContent").CreateNavigator()
    Dim FileContent1 As String = nav1.SelectSingleNode(xpathFC, NamespaceManager).Value

    Dim xpathPDF As String = "/my:myLocalFields/my:ImagePDF"
    Dim nav3 As XPathNavigator = Me.MainDataSource.CreateNavigator()
    Dim FileContent3 As String = nav3.SelectSingleNode(xpathPDF, NamespaceManager).Value

    ' File Name
    Dim time As String = DateTime.Now.ToString("ddMMyyyyhhmmss")
    Dim fileName As String = "File" + time
    Dim data As Byte() = Convert.FromBase64String(FileContent1)
    ' Write the file
    Dim outfile As System.IO.FileStream
    outfile = New System.IO.FileStream("C:\temp\temp\" + fileName + ".pdf", System.IO.FileMode.Create, System.IO.FileAccess.Write)
    outfile.Write(data, 0, data.Length - 1)
    outfile.Close()

    'Write to Form
    DeleteNil(nav3)
    'Cannot run - Gets "Value of type '1-dimensional array of Byte' cannot be converted to 'String'. "
    'nav3.SelectSingleNode(xpathPDF, NamespaceManager).SetValue(data)

    'Fails  - gets "Schema validation found non-data type errors."
    'nav3.SelectSingleNode(xpathPDF, NamespaceManager).SetValue(FileContent1)

     

Page 1 of 1 (1 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.