cancel
Showing results for 
Search instead for 
Did you mean: 

Is it possible to generate a PDF and send it as a mail attachment ?

Former Member
0 Kudos

Hello All,

While there are many contributions and suggestions on how to send a pdf form via email, I will like to find out if its possible to send a pdf as part of an email attachment WITHOUT even viewing it first ? Below is a brief descrption of what I'll like to do :

1) A user logs into his inbox and checks if there are any requests for his approval. In the event that he finds one, he may either select the row item in the table to display the requests details prior to approving or clicks on approve immediately.

2) This approval action should send an email to an appointed external supplier with the request details as a pdf attachment.

All this should be done without the need to generate a interactive form. Is this possible ?

Thank you very much.

from

Kwok Wei

Accepted Solutions (0)

Answers (6)

Answers (6)

Former Member
0 Kudos

Hi Kwok,

Any luck i am trying the same like, i have an java web dynpro application with interactive form, on send button click i need to send the filled form as an pDf attchment to internet mail id. I am using SO_NEW_DOCUMENT_ATT_SEND_API1 inside workflow to send attachment. My custom RFC which is interacting with WD app is getting the pdf source context attribute(simply i set the import parameter with that attribute and no juggling is done) as import parameter which is of type XTSRING. Once i execute the application i am getting mail with attachment as pdf but i am not able to open the pdf. It is of just 1 KB size. It seems my pdf source context attribute is not sending data. Can you pls suggest how can i solve this.DO i need to convert the data to pdf format before sending or any otgher thing i need to do.

Regards

Ravindra

Former Member
0 Kudos

Hi colleagues

Of course you have to generate the pdf, but this is easy(see below).

We use "SO_NEW_DOCUMENT_ATT_SEND_API1", cause the system is not configured to send mail, so we call the fm via rfc on a different system.

0.call function 'FP_FUNCTION_MODULE_NAME'

EXPORTING

i_name = 'Z_MY_ADOBE_IAF'

IMPORTING

e_funcname = fm_name.

1... open spool job (FP_JOB_OPEN)

2.call function fm_name (the Interactive Form you created in SFP)

EXPORTING

/1bcdwb/docparams = fp_docparams

FORMDATA = wa_data

IMPORTING

/1BCDWB/FORMOUTPUT = fp_formoutput

EXCEPTIONS

usage_error = 1

system_error = 2

internal_error = 3

others = 4.

3. close spool job (FP_JOB_CLOSE)

4.CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

EXPORTING

buffer = fp_formoutput-PDF "PDF file from function module

TABLES

binary_tab = lt_att_content_hex.

5.describe table lt_att_content_hex lines lf_lines.

clear la_mailpack.

la_mailpack-transf_bin = 'X'.

la_mailpack-head_start = 1.

la_mailpack-head_num = 1.

la_mailpack-body_start = 1.

la_mailpack-doc_type = 'PDF'.

la_mailpack-body_num = lf_lines.

la_mailpack-doc_size = lf_lines * 255.

la_mailpack-obj_descr = 'object'.

la_mailpack-obj_name = 'MAIL'.

append la_mailpack to lt_mailpack.

6. <u>now fill your hex-data not into contents_bin(obsolet), but in contents_hex</u>:

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1' destination 'mailsystem'

EXPORTING

DOCUMENT_DATA = la_maildata

  • PUT_IN_OUTBOX = ' '

COMMIT_WORK = 'X'

  • IMPORTING

  • SENT_TO_ALL =

  • NEW_OBJECT_ID =

TABLES

PACKING_LIST = lt_mailpack

OBJECT_HEADER = lt_mailhead

  • CONTENTS_BIN =

CONTENTS_TXT = lt_mailtxt

CONTENTS_HEX = lt_att_content_hex

  • OBJECT_PARA =

  • OBJECT_PARB =

RECEIVERS = lt_receiver

This works for our case

Former Member
0 Kudos

Hello Hubertus,

Are you able to open the attached pdf file in the mail with this code?

Thanx

munishsb
Participant
0 Kudos

Hi Hubert,

I am tryign the same logic as ur to send PDF as an attachement but while opening its giving me file cannot be opened.

My code goes like this

CALL FUNCTION 'FP_JOB_CLOSE'

IMPORTING

E_RESULT = RESULT

EXCEPTIONS

USAGE_ERROR = 1

SYSTEM_ERROR = 2

INTERNAL_ERROR = 3

OTHERS = 4.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ELSE.

*********************************************************

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

EXPORTING

buffer = FORM_OUT-PDF "PDF file from function module

TABLES

binary_tab = lv_output.

DATA: GD_DOC_DATA TYPE SODOCCHGI1,

lt_mailpack TYPE STANDARD TABLE OF SOPCKLSTI1 ,

la_mailpack type SOPCKLSTI1 .

data:lf_lines type i.

describe table lv_output lines lf_lines.

clear la_mailpack.

la_mailpack-transf_bin = 'X'.

la_mailpack-head_start = 1.

la_mailpack-head_num = 1.

la_mailpack-body_start = 1.

la_mailpack-doc_type = 'PDF'.

la_mailpack-body_num = lf_lines.

la_mailpack-doc_size = lf_lines * 255.

la_mailpack-obj_descr = 'object'.

la_mailpack-obj_name = 'MAIL'.

append la_mailpack to lt_mailpack.

data: IT_RECEIVERS type STANDARD TABLE OF SOMLRECI1 WITH HEADER LINE.

*DATA: GD_DOC_DATA TYPE SODOCCHGI1.

BREAK FTABAP.

GD_DOC_DATA-OBJ_DESCR = 'PDF'.

IT_RECEIVERS-RECEIVER = 'email address'.

IT_RECEIVERS-REC_TYPE = 'U'.

APPEND IT_RECEIVERS.

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = GD_DOC_DATA

  • * PUT_IN_OUTBOX = ' '

COMMIT_WORK = 'X'

  • * IMPORTING

  • * SENT_TO_ALL =

  • * NEW_OBJECT_ID =

TABLES

PACKING_LIST = lt_mailpack

*OBJECT_HEADER = lt_mailhead

  • * CONTENTS_BIN =

*CONTENTS_TXT = lt_mailtxt

CONTENTS_HEX = lv_output

*

  • * OBJECT_PARA =

  • * OBJECT_PARB =

RECEIVERS = IT_RECEIVERS.

Kindly please help me in solving this issue.

Former Member
0 Kudos

Why don't you check the sample code provided by SDN in the following example :-

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webdynpro/tutorial on offline interactive pdf form using e-mail - 31.htm

former_member186143
Active Contributor
0 Kudos

perhaps look at topic for ABAP solution

I have used it successfully to print a form to a spool which is converted to pdf without the user having any other action then 'to push the button'

Former Member
0 Kudos

In the adobe form you have also a standard buttun for emailing the form

Former Member
0 Kudos

Hi Dresen,

I am trying to to generate the PDF without lauching the interactive form, hence I do not have the option of using that standard button unfortunately.

from

Kwok Wei

Former Member
0 Kudos

Hello All,

The cause of the problem seems to stem from the failure to get the template file as InputStream. In the tutorial,

it suggested using :

InputStream templateSourceInputStream = getClass().getClassLoader().getResourceAsStream("d:
usr
sap
pdf
PDFPreviewView_InteractiveForm1.xdp");

but this will generate a NullPointerException. Is someone able to tell me what may be the problem ?

from

Kwok Wei

Former Member
0 Kudos

Hai Kwok Wei Ng

instead of using the STEP1 code use STEP2 code

STEP1: InputStream templateSourceInputStream = getClass().getClassLoader().getResourceAsStream("d:
usr
sap
pdf
PDFPreviewView_InteractiveForm1.xdp");

STEP2: InputStream pdfSourceInputStream = new FileInputStream(new File("d:
usr
sap
pdf
PDFPreviewView_InteractiveForm1.xdp"));

Regards

Siva Sankar N

Former Member
0 Kudos

Hi Kwok Wei,

Did u find the solution if so Please tell how?

Best Wishes,

Idhaya R

Former Member
0 Kudos

Here is another way to do without using BCS:

1. Write a print program to call the generated FM and send this to spool.

2. In the spool list you will see the pdf file.

3. You can pick the file and do the rest of the things.

4. In the project what we did we moved the file to adobe livecycle to apply policy and then email to the end user.

Hope this helps!!

markus_meisl
Active Contributor
0 Kudos

Hi Kwok Wei,

if you want to send a PDF by mail, at some point you will have to generate a form (whether interactive of not).

Obviously, you can do that in the background, but you will have to follow either the way described in the Web Dynpro for Java tutorial mentioned in the other reply, or or through BCS in ABAP.

Kind regards,

Markus Meisl

SAP NetWeaver Product Management

Former Member
0 Kudos

I guess Markus words good enough for me. Thanks everyone for the suggestions.

Btw Markus, may I ask whats BCS ?

markus_meisl
Active Contributor
0 Kudos

Tools to send attachments from and receive them in ABAP: http://help.sap.com/saphelp_nw04s/helpdata/en/24/370b374e4e7c64e10000009b38f839/frameset.htm

(under NetWeaver > Key Capabilities > Business Services)

Cheers,

Markus

Former Member
0 Kudos

Hi Markus

I am looking for a way to generate a pdf with ADS in the background without displaying the pdf as an interactive form. You were referring to some tutorial (webdynpro/java) in your reply to Kwok's question. Where can I get this tutorial?

Thanks a lot in advance.

Best regards

Bettina Hepp

Former Member
0 Kudos

Hi Kwok Wei

We tried something similar on the Java stack using PDF Object services and the mail APIs , you will have to improvise over this example

<a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webdynpro/tutorial%20on%20working%20with%20the%20pdf%20document%20object%20-%2032.htm">example</a>

Regards

Pran

Former Member
0 Kudos

Thanks Pran. Does any fellow experts here have other suggestions apart from the wan that Pran offered ? I was hopeing for something much simpler.

from

Kwok Wei

Former Member
0 Kudos

Hello Guys,

I had a go at the exmaple that was suggested by Pran and seems to be stuck @ the part of pdfObject.createPDF . It appears that my pdfInputStream is a NULL. Does anyone knows why ? My xml and pdf taht is required @ runtime is already stored in the respective folder of my app server. Any help of assistance is appreciated, Thanks !

<u><b>Snippet from Tutorial</b></u>

// create an instance of PdfObject and set the attributes

IWDPDFObject pdfObject = WDPDFObjectFactory.getPDFObject();

pdfObject.setData(dataSourceOutputStream);

pdfObject.setTemplate(templateSourceOutputStream);

pdfObject.setUserName(userName);

pdfObject.setLocale(new Locale(locale));

pdfObject.setUsageRights(null, PDFObject.getAllUsageRights());

pdfObject.setInteractive(true);

// create the PDF and store it as ByteArrayInputStream

ByteArrayInputStream pdfInputStream = (ByteArrayInputStream) pdfObject.createPDF();

if (pdfInputStream != null) {

try {

// Write PDF to hard disk

FileOutputStream fileOutputStream =

new FileOutputStream(new File(pdfTarget));

IOUtil.write(pdfInputStream, fileOutputStream);

fileOutputStream.flush();

fileOutputStream.close();

returnValue = true;

}

catch(Exception e) {

throw new EJBException(e.getMessage()); }

return(returnValue);

}

from

Kwok Wei

Former Member
0 Kudos

HiPran,

I am not able find the example it is telling

<B> 404-The requested resource is not available. </B>

Please tell me where can i find that example

Best Wishes,

Idhaya R