Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Exist an easy way to convert base64 code in XML files into the original image file on forms

buzrw76
Level 1
Level 1

I've made a form in lifecycle that will be distributed by email as a pdf, and submitted back to me as an XML file and then that data imported into the pdf form template to view the data. Issue is I have an "attach image" field on the form and in XML it gets written to a base64 encoded format. Is there convenient way to extract this code from the XML file so that I would have a workable jpeg image file that I can save and open in other apps? Thank you in advance!  -Robert Tampa

0 Replies
Abhinav_Sharma
Level 4
Level 4

Hi, Sure you can get the image from this Base64 code.

If you are using Livecycle Server ES2 then it would be quite easy. If you are familiar with SET VALUE operation in process, then there is a function getDocFromBase64(/process_data/@strBase64Data) which returns a document of input Base64 string. Note: @strBase64Data is the process variable which holds the Base64 string coming from the PDF form. You can save this document as image file on your disk.

Hope it helps.

Thanks.

-

Abhinav

radzmar
Level 10
Level 10

I tried to make John Brinkman's sample working in reverse.

This script will grab an image field's value and produce an attachment (png-file), which then can be saved to the hard drive.

//Get Base64 data of the image field

var b64Data = ImageField1.value.image.value;

//Convert to a read stream

var ReadStream = util.streamFromString(b64Data);

//Decode from Base64

var DecodedStream = Net.streamDecode(ReadStream, "base64");

//Attach an empty image file

event.target.createDataObject("MyExportImage.png", "", "image/png");

//Update attached image file with stream data

event.target.setDataObjectContents("MyExportImage.png", DecodedStream);


//Show attachment pane

event.target.viewState = {overViewMode:7};

This works so far, but the produced images are always cutted off.

No idea what's the reason for this behavior.

buzrw76
Level 1
Level 1

Hi Abhinav, thank you for the response. Unfortunately I'm not familiar with the SET VALUE operation, is that a function in Lifecycle or a coding command in XML?

buzrw76
Level 1
Level 1

Radzmar, thank you for your response. How do I run this script? And thank you again in advance

radzmar
Level 10
Level 10

Just put it into the click event of a button.

As far as I could figure out, this method seems to work properly only if the image data size is less than about 100 KB.