Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session

Is there a way to insert pdf into image field?

Avatar

Level 2

Bascially Im trying to add the image or pdf dynamically similar to the Acrobat importIcon() function which I used to insert pdf,image, and other stuff. But the acrobat uses a button to insert image or pdf and now Im switching over to Livecycle, Im currently using image field to insert images but is there a way make it so it can accept pdf as well? If you can suggest any other way to insert both image and pdf dynamically, it would be great too.

3 Replies

Avatar

Level 10

Hi,

Would you be able to use importDataObject to read the image and/or pdf file ?  You can try it with this code in the click event of a button.

event.target.importDataObject("name");

This will allow you to select any file type.  What do you need to do with the files once they are read into the form?

Bruce

Avatar

Level 2

Thank you for the reply,

basically I would like to allow user to dynamically insert/embed either image or pdf into my form. The files are just for display, the file size of the pdf does not matter much since it used locally.

Avatar

Level 10

I'm still not sure what functionality importIcon() gives you for a PDF file,  but if you had a button with the following code to attach the PDF or image (if it is an image (at least a jpg) then an image field, ImageField1, also gets populated)

if (event.target.importDataObject("name")) // if user did not cancel the "select a data file to import" dialog

{

    var attachmentObject = event.target.getDataObject("name");

    var filetype = attachmentObject.path.substring(attachmentObject.path.lastIndexOf(".") + 1);

    if (filetype === "jpg")

    {

        var imageStream = event.target.getDataObjectContents("name");

        var imageStreamEncoded = Net.streamEncode(imageStream, "base64");

        ImageField1.rawValue = util.stringFromStream(imageStreamEncoded);  

    }

}

Then you could have another button with the following code to allow the user to view it.

event.target.exportDataObject({ cName: "name", nLaunch: 2 });

If you have multple files to attach then each will have to have a different name property "name" in the example above

Hope this helps

Bruce