Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Convert OTF to PDF and attach to email

Hello everyone,

I'm having some troubles converting a spool order i have to pdf and then sending as an attachment via email.

The problem is with bitmap images that are included in the sapscript of the form used in the spool order.

When i receive the email and open the pdf, Adobe Reader warns me that the pdf is not correct, and shows me the form without images.

This is my code. Am i doing anything wrong ?

CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'

EXPORTING

src_spoolid = gd_spool_nr

no_dialog = c_no

dst_device = c_device

IMPORTING

pdf_bytecount = gd_bytecount

TABLES

pdf = it_pdf_output

EXCEPTIONS

err_no_otf_spooljob = 1

err_no_spooljob = 2

err_no_permission = 3

err_conv_not_possible = 4

err_bad_dstdevice = 5

user_cancelled = 6

err_spoolerror = 7

err_temseerror = 8

err_btcjob_open_failed = 9

err_btcjob_submit_failed = 10

err_btcjob_close_failed = 11

OTHERS = 12.

CHECK sy-subrc = 0.

LOOP AT it_pdf_output INTO is_pdf_output.

TRANSLATE is_pdf_output USING ' ~'.

CONCATENATE output is_pdf_output

INTO output IN CHARACTER MODE.

ENDLOOP.

TRANSLATE output USING '~ ' .

CALL FUNCTION 'SCMS_STRING_TO_XSTRING'

EXPORTING

text = output

mimetype = 'APPLICATION/PDF'

IMPORTING

buffer = outputx.

CHECK NOT outputx IS INITIAL.

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

EXPORTING

buffer = outputx "PDF file from function module

TABLES

binary_tab = lt_att_content_hex.

CLASS cl_bcs DEFINITION LOAD.

DATA:

lo_send_request TYPE REF TO cl_bcs VALUE IS INITIAL.

lo_send_request = cl_bcs=>create_persistent( ).

    • Message body and subject*

DATA:

lt_message_body TYPE bcsy_text VALUE IS INITIAL,

lo_document TYPE REF TO cl_document_bcs VALUE IS INITIAL.

APPEND 'Dear Supplier,' TO lt_message_body.

APPEND ' ' TO lt_message_body.

APPEND

'email text message body.'

TO lt_message_body.

APPEND ' ' TO lt_message_body.

APPEND 'Thank you,' TO lt_message_body.

lo_document = cl_document_bcs=>create_document(

i_type = 'RAW'

i_text = lt_message_body

i_subject = 'Payment Notice' ).

DATA: lx_document_bcs TYPE REF TO cx_document_bcs VALUE IS INITIAL.

TRY.

lo_document->add_attachment(

EXPORTING

i_attachment_type = 'PDF'

i_attachment_subject = 'PaymentNotice'

    • I_ATTACHMENT_SIZE =*

    • I_ATTACHMENT_LANGUAGE = SPACE*

    • I_ATT_CONTENT_TEXT =*

    • I_ATTACHMENT_HEADER =*

i_att_content_hex = lt_att_content_hex ).

CATCH cx_document_bcs INTO lx_document_bcs.

ENDTRY.

    • Add attachment*

    • Pass the document to send request*

lo_send_request->set_document( lo_document ).

    • Create sender*

DATA:

lo_sender TYPE REF TO if_sender_bcs VALUE IS INITIAL,

l_send TYPE adr6-smtp_addr VALUE 'test @ webserver.com'.

lo_sender = cl_cam_address_bcs=>create_internet_address( l_send ).

    • Set sender*

lo_send_request->set_sender(

EXPORTING

i_sender = lo_sender ).

    • Create recipient*

DATA:

lo_recipient TYPE REF TO if_recipient_bcs VALUE IS INITIAL.

    • lo_recipient = cl_sapuser_bcs=>create( sy-uname ).*

lo_recipient =

cl_cam_address_bcs=>create_internet_address( ls_email ).

      • Set recipient*

lo_send_request->add_recipient(

EXPORTING

i_recipient = lo_recipient

i_express = 'X' ).

lo_send_request->add_recipient(

EXPORTING

i_recipient = lo_recipient

i_express = 'X' ).

    • Send email*

DATA: lv_sent_to_all(1) TYPE c VALUE IS INITIAL.

lo_send_request->send(

EXPORTING

i_with_error_screen = 'X'

RECEIVING

result = lv_sent_to_all ).

COMMIT WORK.

MESSAGE

'Email was sent to Supplier'

TYPE 'I'.

Tags:

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question