Including attachments from PDF in Save as Draft and Submit as XDP

When I wrote the first large process years ago, I ran into the problem of saving attachments that are in the PDF. If you ask the question, the response will be that you have to submit as PDF. That in turn has it's own other problems which when trying to solve, the answer given is "That is because you are submitting as a PDF". I have seen many ask the same thing I wanted: Submit as XDP, but include the attachments. This also includes that the built in Save Draft save them too.
The summary is this: Loop through the attachments in JavaScript, Base64 encode them and stick them into the DOM. On the server side, use a script step to loop through and create a map of document objects to pass to the next render.
The following needs to be called from a preSubmit event passing event.target. You'll need to add the nodes referenced to your schema.
function embedAttachments(oParent) {
    // Get the list of attachments
    var oDataObjects = oParent.dataObjects;
    //app.alert(oDataObjects);
    var rootNode = xfa.datasets.data.resolveNode("[Your Data Root Node]");
    var oAttachData = rootNode.nodes.namedItem("FileAttachments");
    var oldNodes = oAttachData.nodes;
    //wipe out empty nodes
    while (oldNodes.length != 0) {
      oldNodes.remove(oAttachData.nodes.item(0));
    if (oDataObjects != null) {
      var count = oDataObjects.length;
      if (count > 0) {
          // Loop through all the attachments
          for (var i = 0; i < count; i++) {
            // Grab the next attachment
            var oFile = oParent.getDataObjectContents(oDataObjects[i].name);   
              // Get a new stream with the image encoded as base64
            var vEncodedStream = Net.streamEncode(oFile, "base64");
            // Get a string from the stream
            var sBase64 = util.stringFromStream(vEncodedStream);
              //console.println(sBase64);
              // Copy the data to the XML
            var oNewNode = xfa.datasets.createNode("dataGroup", "FileAttachment");
            oAttachData.nodes.append(oNewNode);
            var oName = xfa.datasets.createNode("dataValue", "FileName");
            var oDesc = xfa.datasets.createNode("dataValue", "FileDesc");
            var oData = xfa.datasets.createNode("dataValue", "Base64Data");
            oName.value = oDataObjects[i].path;
            oDesc.value = oDataObjects[i].description;
            oData.value = sBase64;
            oNewNode.nodes.append(oName);
            oNewNode.nodes.append(oDesc);
            oNewNode.nodes.append(oData);   
It also needs to be called from ContainerFoundation_JS in the form bridge.
Add this variable:
var thisDoc = null;
Add this line of code at the top of RegisterMessageHandler:
    thisDoc = event.target;
Add this line of code to the top of getData function:
xfa.form.[Root Node].[Script Object].embedAttachments(thisDoc);
Here is the Java code to add to a script object. I put mine in a custom render.
import java.util.HashMap;
import java.util.*;
import org.w3c.dom.*;
import com.adobe.idp.Document;
import org.apache.commons.codec.binary.Base64;
int count = 0;
Map attachmentMap = new HashMap();
Node ndAttach = patExecContext.getProcessDataValue("/process_data/xmlData/Formdata/FileAttachments");
if (ndAttach != null) {
    NodeList children = ndAttach.getChildNodes();
    if (children != null) {
        count = children.getLength();
for (int i = 1; i <= count; i++){
    String name = patExecContext.getProcessDataStringValue("/process_data/xmlData/Formdata/FileAttachments/ FileAttachment[" + i + "]/FileName");
    String desc = patExecContext.getProcessDataStringValue("/process_data/xmlData/Formdata/FileAttachments/ FileAttachment[" + i + "]/FileDesc");
    String b64Data = patExecContext.getProcessDataStringValue("/process_data/xmlData/Formdata/FileAttachments/ FileAttachment[" + i + "]/Base64Data");
    if (b64Data != null && b64Data.length() != 0) {
        Document attDoc = new Document((new Base64()).decode(b64Data.getBytes()));
        attDoc.setAttribute("basename", name);
        attDoc.setAttribute("description", desc);
        attDoc.setAttribute("wsPermission", "1");
        attDoc.passivate();
        attachmentMap.put(name, attDoc);
patExecContext.setProcessDataMapValue("/process_data/mapAttachments", attachmentMap);
After I wrote that, I realized there is a method to create a document from Base64. Since I can inspect the map during record and play back and see that the documents are stored Base64, I think I could speed up the process by changing to the other method. I am assuming it would prevent a decode then encode. This same technique might also be applied to annotations.

Revised Execute script. Server was running out of heap space with large attachments. Creating the Document objects as temp files instead of in memory solves that. I also added the part that wipes the Base64 Attachments out of the XML.
        int count = 0;
        Map attachmentMap = new HashMap();
        String name="";
        String b64Data="";
        File tempFile=null;
        FileOutputStream outStream=null;
        Document attDoc=null;
        int i=0;
        Node ndAttach = (Node) patExecContext.getProcessDataValue("/process_data/xmlData/Formdata/FileAttachments");
        NodeList children;
        Node childNode = null;
        if (ndAttach != null) {
            children = ndAttach.getChildNodes();
            if (children != null) {
                childNode = children.item(i);
                if (childNode instanceof Element) {
                    System.out.println("tag name: " + ((Element)childNode).getTagName());
                count = children.getLength();
        for (i = 1; i <= count; i++){
            b64Data = patExecContext.getProcessDataStringValue("/process_data/xmlData/Formdata/FileAttachments/FileAttachment[" + i + "]/Base64Data");
            if (b64Data != null && b64Data.length() != 0) {
                name = patExecContext.getProcessDataStringValue("/process_data/xmlData/Formdata/FileAttachments/FileAttachment[" + i + "]/FileName");
                tempFile = File.createTempFile("Attachment", ".tmp");
                outStream = new FileOutputStream(tempFile);
                outStream.write(Base64.decodeBase64(b64Data.getBytes()));
                outStream.close();
                attDoc = new Document(tempFile, true);
                attDoc.setAttribute("basename", name);
                attDoc.setAttribute("description", patExecContext.getProcessDataStringValue("/process_data/xmlData/Formdata/FileAttachments/FileAttachment[" + i + "]/FileDesc"));
                attDoc.setAttribute("wsPermission", "1");
                attachmentMap.put(name, attDoc);
        patExecContext.setProcessDataMapValue("/process_data/mapAttachments", attachmentMap);
        while (ndAttach.hasChildNodes()) {
            ndAttach.removeChild(ndAttach.getLastChild());

Similar Messages

  • Hello..when I download attachments from any email..iPages opens and says some features are not supported and cuts out photos and lengthens my attachments

    hello..when I download attachments from any email..iPages opens and says some features are not supported and cuts out photos and lengthens my attachments

    What format are the attachments? If Pages will not display them properly you will need an application that does. Pages usually opens word documents but can give problems at times, if they are MS Word documents, try Libre Office or failing that you may have to purchase MS Word for Mac, maybe you will need to buy the complete Office suite.
    The other possiblity is that you already have a suitable application and Pages is loading the file by default, if so change the default application to open that file type.

  • "Include Attachments" option in Mail Save As... Dialog doesn't work

    Back in the day (Lion) the "Include Attachments" check box in the Mail Save As... dialog used to save mail attachments along with the text as .RTFD.  Sometime in the past this changed, and now (Mavericks) the only affect of checking that box is that the extension of the saved file changes from .RTF to .RTFD, but the saved file remains identical, with only the text and no attachments.  Surely this is a bug.  Is there now any way to save an email as RTFD with the attachments?
    I'm bringing this up again since the previous thread on the subject was archived back in 2012 without any comprehension.  Time for a revisit.

    You should post here:
    Microsoft Office forums >
    Word IT Pro Discussions
    S.Sengupta, Windows Entertainment and Connected Home MVP

  • Adobe Acrobat X - convert outlook email to pdf and include attachments as pdf

    Is there a way to save an Outlook email as a PDF and include attachments as extra pages within the same PDF? I know I can convert an email to PDF and it will include the attachments as links.  My end users feel that their clients won't understand the link feature, and/or the paper clip on the side pane.  They'd rather convert an email and have it's attachments converted also, making the pdf an email message + converted attachments....all in one process.  The only way currently is to open each attachment and convert them individially, then combine the email pdf and attachment pdf together.  Too many steps involveed there.
    make sense?
    Thanks,
    Jon Wooten

    Same question here, but for Lotus Notes!! Seems ridiculously simple.

  • Get attachments from pdf

    I have a problem that is urgent. I want to extract attachements from a pdf file using java apis. I started from an example buf the BIG problem is that i don't have a documentation for certain java classes.<br />A piece of my code:<br /><br />PDFDocument pdfDoc = pdfFactory.openPDF(pdfFile);<br />try{<br />      EmbeddedDataObject[] edoList = pdfDoc.getDataObjectList();<br />      if (edoList.length>0){<br />         for(int i=0;i<edoList.length;i++){<br />        try{<br />           DataBuffer edodb = pdfDoc.exportDataObject(edoList[i].name);<br /><br />        }<br />        catch (Exception e){}<br />}<br />catch (Exception e){}<br /><br />DataBuffer is com.adobe.service.DataBuffer, buf i can't find documentation for it.<br />Please help.<br /><br />Regards, bogdan

    If you need code-level help, you should open a formal support incident with our Developer Support folks.
    From: Adobe Forums <[email protected]<mailto:[email protected]>>
    Reply-To: "[email protected]<mailto:[email protected]>" <[email protected]<mailto:[email protected]>>
    Date: Tue, 24 Jan 2012 23:13:52 -0800
    To: Leonard Rosenthol <[email protected]<mailto:[email protected]>>
    Subject: How to get file attachments from a pdf.
    Re: How to get file attachments from a pdf.
    created by poortip87<http://forums.adobe.com/people/poortip87> in Acrobat SDK - View the full discussion<http://forums.adobe.com/message/4163393#4163393

  • As soon as I type in subject line of email, it tries to save as draft and crashes.

    I'm running Windows 8 on a ASUS laptop (new within the past few months). I access iCloud mail from my PC, iPhone and iPad Mini. The problem only happens using iCloud Mail on my PC.
    Just within the past few weeks, as soon as I begin typing a subject line in mail, I get a pop-up question "Save this message as a draft?" 
    If I  Don't Save it, it kicks me out of the message.
    If I Cancel it, it takes me back to the message, but asks me again with the next key stroke and keeps asking until I move out of the subject line.  So I am being constantly interrupted while I'm in the subject line.
    If I Save it, it does save, but closes the message.
    It appears that Don't Save and Save are doing what they are supposed to, but Cancel just takes me back to the message only to be interrupted over and over.
    Is there some way to get it to quit prompting me to save a draft?

    I belive the issue is with quotes..try removing the double quotes " " or try using single quotes ' ',either removing the quotes completly or using single quotes should work..let us know if it works..

  • Convert attachments from pdf to jpeg

    I received some photos as pdf attachments and i need to convert them to jpeg to save them in my iPhoto library

    Drag the Preview application from your Applications folder to the Dock, if it is not already there.
    Then save the attachments to your Desktop from Mail.
    Drag each attachment to the Preview icon to open it in Preview.
    Alternately, you can right-click or ctrl-click a document and use the command "Open with" from the contextual menu to force the document to open in a specific application.

  • Retreiving attachments from PDF

    As you know, attachments can be added to PDF forms. I would like to know how can I retrieve these attachments and use them in Workbench ?
    Thanks
    Aditya

    I am using:
    Category: Forms
    Service Name: FormsService
    Service Operation: processFormSubmission
    The attachments come in off that as a list. I am then using the following script to move into a map for use in a later render:
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    import java.util.Iterator;
    import com.adobe.idp.Document;
    List attachmentList = patExecContext.getProcessDataListValue("/process_data/lsAttachments");
    Map attachmentMap = new HashMap();
    Iterator it = attachmentList.iterator();
    while(it.hasNext()){
    Document attDoc = (Document) it.next();
    String name = (String) attDoc.getAttribute("name");
    attachmentMap.put(name, attDoc);
    patExecContext.setProcessDataMapValue("/process_data/attachments",attachmentMap);
    attachmentList.clear();
    patExecContext.setProcessDataListValue("/process_data/lsAttachments", attachmentList);

  • Mail changes my attachments from PDFs to Jpegs - Help!!

    I have to send PDF visuals to my clients but sometimes when I attach the PDF to the email, Mail converts it to a Jpeg, which is no good as it looks crap at the other end. Has anyone else seen this ? Is there a way to stop it ?

    Hello, and welcome to the Discussions.
    I have produced this problem, but only when having first attached another file, and used the size button to reduce the size from Actual. After the change from Actual Size, then a PDF would be presented as a JPEG.
    However, in all tests, if the first act of attachment was the PDF, the starting position was Actual Size, and the PDF remained a PDF file. You cannot use the Size button to reduce the size of PDF files, but must go other routes.
    I have reported this behavior, however, the only problem in my opinion, is that a file type can be changed without warning, and not the function of this size button. The size button is really intended to allow easy resizing of photos, and probably should be limited to photos. For example, if a .tif file were switched to .jpg, it is still an image, and convenient size to send is made possible.
    More info, please, about your exact experience.
    Ernie

  • When i am sending an email include attachments from my IPhone its receive by image not attached file

    Dear All,
    Greeting
    i am hope receive any answer to solve my proplem

    Posting this as it took me forever to find the fix.  No one with my carrier, Apple etc. seemed to know of the fix or for that matter even recognize that it was an issue. Hopefully this will help someone else.  This is for Exchange 2010
    Log on to the Exchange server hosting OWA
    start run cmd, right click on the cmd and choose run as adminsitrator
    cd C:\Windows\System32\inetsrv\
    appcmd.exe set config -section:system.webServer/serverRuntime /uploadReadAheadSize:"16000000" /commit:apphost
    appcmd.exe set config "Default Web Site" -section:system.webServer/serverRuntime /uploadReadAheadSize:"16000000" /commit:apphost
    restart IIS
    Note that 1600000 should be the size of the allowed email in bytes.

  • Automator application: Rtf's converted from pdf's do not open and word files from same rtf's are blank--???

    I found directions for converting pdf's to word documents to facilitate editting.  The process used Automator by selecting
    pdf's to be converted to rtf's.  The resulting rtf file could then be saved as a word document.  The problem is that the resulting
    rtf's do not open and the saved word document opens blank.  What's the problem and the solution?

    mns579 is correct, but it is even more complex than that. To put it bluntly, the only thing a PDF is guaranteed to do is print. There is no guarantee that any PDF will convert into any format other than an image (for printing). Some PDFs are composed of actual text or vector data and those are nice to work with, but not commonly encountered. In fact, pretty much the only time you are likely to have a PDF in a format that can be easily converted is when you have the document in some other original format from which you made the PDF. And, if you have said original format, why do you need PDF?

  • How do I get my playlist songs from iTube to save on phone and does that cost do save on phone?

    I Use iTube for music but I want to know how I save the songs to my phone and does it cost to save the songs to my phone after I put them
    into my playlust

    russellfromblackburn south wrote:
    Is it because the portable drive is NTFS format and the Mac wont recognise this? If so what do I do?
    Yes, this is exactly what is causing the problem. Macs cannot write to NTFS formatted drives, only read. You must move the documents to the internal HDD/SSD of the Mac to be able to edit them.
    Or, since you say you don't want to move the documents to the internal storage, you'll need to format the external HDD as FAT32.

  • Time Sheet Draft and submit

    Hi
    I have configured Time recording along with a standard cats timesheet. The  the user wants to create his timesheet in draft version. I checked in SPRO configuration,is there any way to do it.
    In the actual configuration employee inserts his timesheet, checks his time data a final time, released his data that his transferred to his superior.
    is There any possibility to create the data in draft mode and then submit the request If required?
    Thanks,
    Nachy

    Nachy,
    you dont have such option with the standard functionality.you can use Save as template which will just save the att/abs type not the hours .
    Thanks
    Bala Duvvuri

  • Ess Timesheet Draft and submit

    Hi
    I have configured Time recording along with a standard cats timesheet. The the user wants to create his timesheet in draft version. I checked in SPRO configuration,is there any way to do it.
    In the actual configuration employee inserts his timesheet, checks his time data a final time, released his data that his transferred to his superior.
    is There any possibility to create the data in draft mode and then submit the request If required?
    Thanks,
    Nachy

    We used no automatic release using the TCATS table.

  • Include attachments in a xml file without using mail adapter

    Hello Experts,
    Is there a way to include attachments like pdf or excel in a xml file?
    It is a file to file scenario in which i have to include the attachment in the output file.
    Thanks and regards,
    Merrilly

    Hi,
    Check this links,
    PDF
    SAP Network Blog: XI: Read data from PDF file in Sender Adapter
    /people/sap.user72/blog/2005/07/31/xi-read-data-from-pdf-file-in-sender-adapter
    SAP Network Blog: XI: Generate PDF file out of file adapter
    /people/sap.user72/blog/2005/07/27/xi-generate-pdf-file-out-of-file-adapter
    EXCEL FILES
    SAP Network Blog: XI: Generating Excel files without the Java nor the Conversion agent not possible?
    /people/michal.krawczyk2/blog/2005/12/10/xi-generating-excel-files-without-the-java-nor-the-conversion-agent-not-possible
    SAP Network Blog: Read Excel instead of XML through FileAdapter
    /people/sap.user72/blog/2005/07/04/read-excel-instead-of-xml-through-fileadapter
    Regards,
    Phani
    Reward points if Helpful

Maybe you are looking for