These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Image field in a form

hasligrove
Registered: Jul 28 2011
Posts: 1

I have created a form with several image fields. I'm trying to figure out how to extract the image from the form. Basically the customer is inserting an image on the form and then returning to me. When I get the form I can see the image but I need to be able to save the image on my computer. I thought embeding the image would work but I must be missing something.

My Product Information:
LiveCycle Designer, Windows
radzmar
Expert
Registered: Nov 3 2008
Posts: 1202
Hi,

generally it could work with the functions Acrobat already has build in, generally.
But, it isn't that simple.
This script will recover images from image fields and save it as attachment to the pdf.
But, this would be to good to be true.
There is a problem in the streamDecode function, which causes incomplete images when their size is larger than 50KB.
  1. var Number = "0";
  2. if (event.target.dataObjects !== null)
  3. {
  4. Number = event.target.dataObjects.length.toString();
  5. }
  6. var fileExtension = ImageField1.value.image.contentType.replace("image/", ".");
  7. var b64Data = ImageField1.value.image.value;
  8. var ReadStream = util.streamFromString(b64Data);
  9. var DecodedStream = Net.streamDecode(ReadStream, "base64");
  10. var NewAttachmentName = "MyExportImage_" + Number + fileExtension;
  11. event.target.createDataObject(NewAttachmentName, "", "image/png");
  12. event.target.setDataObjectContents(NewAttachmentName, DecodedStream);
  13.  
  14. event.target.viewState = {overViewMode:7};
So, you have to do a work around.
If the images are embeded you can read out the base64 encoded data, convert it into a stream object which then can be stored in a txt attachment.

This script will do this.
  1. var Number = "0";
  2. if (event.target.dataObjects !== null)
  3. {
  4. Number = event.target.dataObjects.length.toString();
  5. }
  6. var fileExtension = ImageField1.value.image.contentType.replace("image/", ".");
  7. var b64Data = ImageField1.value.image.value;
  8. var ReadStream = util.streamFromString(b64Data);
  9.  
  10. var NewAttachmentName = "MyExportImage_" + Number + fileExtension + ".txt";
  11. event.target.createDataObject(NewAttachmentName, "", "text/plain");
  12. event.target.setDataObjectContents(NewAttachmentName, ReadStream);
  13.  
  14. event.target.viewState = {overViewMode:7};
You then can save the attached txt file to your disk, open it and use an external source to convert the base64 data back into the binary format.
This is also explained here




radzmar
LoveCycle Blog
Documents you need:
LiveCycle Designer ES2 Docs

NK-INC.COM
Registered: Apr 17 2010
Posts: 93
This can also be done using FDFToolkit.net by NK-INC.COM.

Useful links:
http://www.nk-inc.com/Source-Code: VB.net 2.0 to 4.0

Private Function SaveImageFieldToFile(pdfSource as String, pdfImageFieldName as String, imageDestination as String) As Boolean

Dim cFDFApp as new FDFApp.FDFApp_Class
Dim cFDFDoc as new FDFApp.FDFDoc_Class
cFDFDoc = cFDFApp.PDFOpenFromFile(pdfSource)
Dim strImageBase64 as String = cFDFDoc.XDP_GetImageBase64(pdfImageFieldName,false)
Dim bytesImage() as byte = cFDFDoc.ConvertFromBase64ToByte(strImageBase64,cFDFDoc._defaultEncoding)

Dim fs as New System.IO.FileStream(imageDestination,Create,ReadWrite)
fs.Write(bytesImage,0,bytesImage.length)
fs.close()

return True

End function