16 Replies Latest reply: Mar 14, 2011 11:30 AM by Nikesh Shah RSS

Sending Adobe Interactive Forms via Email

Iwan Santoso
Currently Being Moderated

Hi,

 

I have an application displaying the pdf within web dynpro. I would like to add a button that will send the pdf displayed via email.

 

My question is do I have to save the pdf first in a directory within the server?

 

Any idea on what is the best approach for this?

 

Thanks in advance,

Iwan

  • Re: Sending Adobe Interactive Forms via Email
    Nagarajan Kumarappan
    Currently Being Moderated

    Hi,

     

    Yes u can send email to the id which u want.There is a option for creating an email button in interactive forms.Create an email button and change the properties of the button to the id that u want.

     

    u can directly send the form without saving it.<b>But for ur information this email option will send ur pdf in the xml format with the values that u give in the pdf input</b>.U can also send it by saving it.Then this becomes ur offline form.

     

    If u want to send it as a pdf one then it is best to have a button and then write ur java mail code inside the action of it,which might help u in doing this.

     

    Hope this helps u,

    Regards,

    Nagarajan.

  • Re: Sending Adobe Interactive Forms via Email
    Iwan Santoso
    Currently Being Moderated

    Hi Nagarajan,

     

    Thanks. I'm a newbie, can you elaborate more on how to save the pdf in the server? i certainly do not want to save pdf at user pc before sending the email. I knew how to send email from java mail. I just need more explanation on how to save the pdf in the server and then attach it to the email.

     

    Thanks,

    Iwan

    • Re: Sending Adobe Interactive Forms via Email
      Nagarajan Kumarappan
      Currently Being Moderated

      Hi Iwan,

       

      Sorry for the late reply.

       

      Saving the pdf form in pc is very simple.If u run ur interactive forms,in the form u will have the save option (save a copy).Just by clicking on that u can save ur pdf in the local machine.

       

      But in order to send this form as an email then u have to again upload it in ur application and then only u can send it through mail.For this u have to create an upload element in the WD application and then u could do it easily.

       

      Hope this helps u,

      Regards,

      Nagarajan.

  • Re: Sending Adobe Interactive Forms via Email
    Iwan Santoso
    Currently Being Moderated

    Hi,

     

    I'm sorry you misunderstood what i need. The way you described it, is done manually.

     

    Imagine the view in web dypro has Adobe form displayed, below the form there is a button to send the adobe form as an attachement via email and input field as the email address.

     

    I would like the user just type in the email address and click the send button in order to send the form via email. And the email will have a predifined text body and the displayed pdf as attachement.

     

    This can be done 'manually' as you have described, but I want to do it programmatically. Do you have any idea?

     

    Regards,

    Iwan

    • Re: Sending Adobe Interactive Forms via Email
      Markus Meisl
      Currently Being Moderated

      Hi Iwan,

       

      it would probably work best if you program your Web Dynpro application in such a way that when a user enters the e-mail address and clicks on Send, the action triggered by this accesses the same Context node ('pdfSource') as the one you use to display the PDF in the browser.

      The displayed PDF is not persisted anywhere, so it might be complex to actually send this physical PDF instead of one generated by the server (possibly generated again in a second step).

       

      It all depends on your scenario: Does the user always have to look at the form before sending it? Does he enter anything in the generated form before sending it? Does he always send it? You need to know in detail what your process looks like before working with the form.

       

      Kind regards,

      Markus Meisl

      SAP NetWeaver Product Management

      • Re: Sending Adobe Interactive Forms via Email
        Iwan Santoso
        Currently Being Moderated

        Hi Markus,

         

        Thanks for the response. The scenario that I have is to generate the form dynamically. For example the screen has several input fields and based on this input fields will determine how the final pdf looks like. I don't need to send the 'displayed' pdf. I should say I would like to send pdf that is generated at run time.

         

        I am under the assumptiopn that pdfSource contains the source of PDF in binary mode... like when doing sapscript and smartform you can have it as OTF format and covert it to pdf format. In ABAP I send the 'binary' pdf format as an attachment. I would like to do the same.

         

        To re-phrase my question: How can I send the pdfSource as an pdf attachment?

         

        Thanks,

        Iwan

        • Re: Sending Adobe Interactive Forms via Email
          Markus Meisl
          Currently Being Moderated

          Hi Iwan

           

          have you had a look at the e-mail tutorial for Interactive Forms on the Web Dynpro tutorial page?

          http://sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/49f2ea90-0201-0010-ce8e-de18b94aee2d -> Using PDF forms -> Java Mail API

           

          Regards,

          Markus

          • Re: Sending Adobe Interactive Forms via Email
            Iwan Santoso
            Currently Being Moderated

            Hi Marcus,

             

            I did see that tutorial. I stump on the following code:

             

            String filename =

            "temp
            webdynpro
            web
            local
            TutWD_EmailInteractiveForm_Init
            Components
            com.sap.tut.wd.emailinteractiveform.EmailInteractiveFormComp
            TravelRequest.pdf";

            DataSource source = new FileDataSource(filename);

             

            As you can see, the filename is assigned and for this to work correctly, the file should already be saved to that location. Is it possible if the pdf file is generated dynamically. I assume that the pdf file is stored in pdfSource of the context. However I got byte[] is incompatible with DataSource when I am trying to use pdfSource. Any idea?

            • Re: Sending Adobe Interactive Forms via Email
              Henrik Damhøj Andersen
              Currently Being Moderated

              Hi,

               

              I had the same challenge some time ago. I managed to avoid using a physical file by using a Class. It might not be the only solution, but it did the job

               

              messageBodyPart = new MimeBodyPart();
              
              <b>messageBodyPart.setDataHandler(
                   new DataHandler(
                        new MemoryDataSource(
                             wdContext.currentContextElement().getPdfSource())));</b>
              
              messageBodyPart.setFileName(
                   wdContext.currentContextElement().getAttachmentName());
              
              messageBodyPart.setHeader("Content-Type", "application/pdf");
              
              multipart.addBodyPart(messageBodyPart);
              
              message.setContent(multipart);

               

              public class MemoryDataSource implements DataSource {
                   private byte[] data;
                   private String filename;
              
                   public MemoryDataSource(byte[] data) {
                        this.data = data;
                   }
                   public String getContentType() {
                        return "application/pdf";
                   }
                   public InputStream getInputStream() throws IOException {
                             return new ByteArrayInputStream(data);
                   }
                   public void setName(String name) {
                        this.filename = name;
                   }
                   public String getName() {
                        return this.filename;
                   }
                   public OutputStream getOutputStream() throws IOException {
                        return null;
                   }
              }

               

              Best regards,

              Henrik

              • Re: Sending Adobe Interactive Forms via Email
                Jia Jun Ng
                Currently Being Moderated

                Hi Henrik,

                 

                i try to implement your code inside but i still have error on this following fields

                 

                <b>messageBodyPart.setDataHandler(new DataHandler(new MemoryDataSource(wdContext.currentContextElement().getPdfSource())));</b>

                 

                the error it give me is this

                The constructor DataHandler(MemoryDataSource) is undefined

                 

                i try to create the java class as what u type

                 

                package com.sap.example.uploademail;
                
                import java.io.ByteArrayInputStream;
                import java.io.IOException;
                import java.io.InputStream;
                import java.io.OutputStream;
                
                /**
                 * @author Admin
                 *
                 * To change the template for this generated type comment go to
                 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
                 */
                public class MemoryDataSource {
                     private byte[] data;
                          private String filename;
                 
                          public MemoryDataSource(byte[] data) {
                               this.data = data;
                          }
                          public String getContentType() {
                               return "application/pdf";
                          }
                          public InputStream getInputStream() throws IOException {
                                    return new ByteArrayInputStream(data);
                          }
                          public void setName(String name) {
                               this.filename = name;
                          }
                          public String getName() {
                               return this.filename;
                          }
                          public OutputStream getOutputStream() throws IOException {
                               return null;
                          }
                }

                 

                 

                wonder which part i do wrong?

              • Re: Sending Adobe Interactive Forms via Email
                Nikesh Shah
                Currently Being Moderated

                Hi Henrik,

                 

                I am also facing an error :

                 

                the constructor DataHandler(MemoryDataSource) is undefined

                 

                Please let me the what should be done ?

          • Re: Sending Adobe Interactive Forms via Email
            Prasad Sheth
            Currently Being Moderated

            Hello markus, is this possible to use WD for ABAP to send pdf in mail ? Please let me know for any possible examples.

             

            Thanks

            Prasad

      • Re:  Preview Adobe Interactive Forms
        Saujanya GN
        Currently Being Moderated

        Hi,

         

        I have created adobe interactive form for an offline scenario. I looking for the upload functionality.

        I am able to view the xml of the form data. But when i trigger the useraction to view the form, it throws a dump.

         

        I have mapped the pdf source and data source to the pdf source and data_nodes properly.But i m not sure what needs to be filled in the template source, can you please gimme some pointer on this,as i didnt find this example in wd abap in sdn.

         

        I find most of the examples are on wd java.. and i find abit different in wd abap.

         

        Thanks,

        Saujanya

  • Re: Sending Adobe Interactive Forms via Email
    Iwan Santoso
    Currently Being Moderated

    Hi Henrik,

     

    This is what I am looking for. Just one follow up how I can add the class to the project, but do you know how to make other project to use this class?

     

    Thanks again.

     

     

    Message was edited by: Iwan Santoso

     

Actions