3 Replies Latest reply on Jan 25, 2011 7:04 AM by Hodmi

    Adding Image at runtime !

    Abhinav Sharma Level 2



      Can we add Image to the form same like as we do with Floating Fields ?? I need to pass the image path ('C:\images\sample.jpg') & it should be displayed in ImageField.




        • 1. Re: Adding Image at runtime !
          Hodmi Level 4

          This is really more of a Form/Designer question then a Generator question, but I'll do my best to help out:


          I'm assuming that you don't just want the default functionality of an image field (where the user clicks on the field and then browses to the image).  Do you want to do this from the form itself (no server side rendering), or are you adding the image as part of a server side rendering of the form?


          If its in the PDF itself you'll need to make a call to get the image data (such as a web service call), then add it to the image field using some script.  Since you are making a service call and (presumably) saving the form afterwards, you'll need to add Reader Extensions to the document.


          If you are doing it server side, as part of a process, then you will have to do the following:

          • Read the image into a document variable using the "Read Document" operation
          • Convert the image to base64 using a setValue operation and the Document Object Functions "getDocContentBase64" function
          • move the resulting base64 string into the proper place in an XML object (one that matches the form's data)
          • use either Forms, Output or Form Data Integration to render the form with the new data (that includes the image)
          • 2. Re: Adding Image at runtime !
            Abhinav Sharma Level 2

            Thanks Hodmi.


            Yes, I am rendering image at server side. I did the same way you suggested for server side, but it doesn't works.


            Steps I did:

            1. Read JPG image in document variable;
            2. Convert this document to base64 using getDocContentBase64() function, store result string in variable.
            3. Assign this value to imageField.rawValue.


            But this is still not working. I dont know where I am wrong.Pls help.




            • 3. Re: Adding Image at runtime !
              Hodmi Level 4

              Its step 3 that is the issue.   The XML data isn't the same as the XFA field properties (of which .rawValue is one)


              When you created your form, you also created an XML data structure.  If you don't manually bind sample XML or a schema to the form then Designer will create a default one for you.  The default one will follow the same structure of your form, but it will not include the field properties - its just the data.

              Note:  If you are bound your form to a schema or sample XML then it will use that structure rather than the default.


              The easiest way to see what it looks like is to open the form in Desinger.

              • Choose File, Form Properties. 
              • Click on the  Preview tab. 
              • Click on the Generate Preview Data button. 
              • Set the file name and location
              • Click Save
              • Click Generate


              This will save a sample XML file with jiberish standing in for real data.  This is the XML format that you will need to use to insert the base64 data into the field.



              One thing to keep in mind is that you are replacing ALL of the data when you do this type of re-render.  If your form already has data, you will need to extract it (using Process Form Submission) and modify the resulting XML before re-rendering the form.