Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Error opening the PDF file while sending the PDF as an attachment

Former Member
0 Kudos

Hi All,

I am sending a PDF as an attachment in the mail. I am using the code pasted on 'Jul 28, 2006 8:59 AM' subject OTF Format of Purchase Order in email unreadable.

My problem is when I open the attachment in SOST or in the mail, I get the error message "Adobe could not open *.PDF because it is either not a supported file type or because the file type has been corrupted."

Please let me know if anybody has faced such an issue.

The code is found below.

*----


  • FORM MAIL_OBJECT *

*----


  • This routine receives OTF data. OTF data is converted to PDF

  • format and send to the Partner's email address

*----


FORM mail_object TABLES otf_data STRUCTURE itcoo .

DATA: pdf_size TYPE i, " PDF Size

pdf_itab_size TYPE i, " Attachment size

mailtxt_size TYPE i, " Text in mail size

l_vbeln LIKE vbdka-vbeln. " Order Doc

DATA:

it_mailtxt LIKE solisti1 OCCURS 0 WITH HEADER LINE, " Mail Text

it_pdf TYPE TABLE OF tline WITH HEADER LINE, " OTF output

it_mailpack LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE, " Dist details

it_mailhead LIKE solisti1 OCCURS 1 WITH HEADER LINE," Header data

it_reclist LIKE somlreci1 OCCURS 0 WITH HEADER LINE, " Rec List

it_pdfdata LIKE solix OCCURS 0 WITH HEADER LINE. " Attachment data

DATA: it_doc_att LIKE sodocchgi1. " Attri of new doc

DATA: BEGIN OF it_pdfout OCCURS 0, " PDF in 255 length

tline TYPE char255,

END OF it_pdfout.

  • Sales doc and Customer

DATA: BEGIN OF i_vbeln OCCURS 0,

vbeln LIKE vbpa-vbeln, " Sales Document

adrnr LIKE vbpa-adrnr, " Customer

END OF i_vbeln.

  • Sender Address no and SMTP address

DATA: BEGIN OF i_addrs OCCURS 0,

addrnumber LIKE adr6-smtp_addr,

smtp_addr LIKE adr6-smtp_addr,

END OF i_addrs.

  • Convert OTF to PDF

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

format = 'PDF'

IMPORTING

bin_filesize = pdf_size

TABLES

otf = otf_data

lines = it_pdf.

  • Make each line 255 characters

CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'

TABLES

content_in = it_pdf

content_out = it_pdfout.

  • Create the PDF File

CLEAR it_pdfdata.

REFRESH it_pdfdata.

  • it_pdfdata[] = it_pdfout[].

LOOP AT it_pdfout.

MOVE it_pdfout-tline TO it_pdfdata-line.

APPEND it_pdfdata.

CLEAR it_pdfdata.

ENDLOOP.

DESCRIBE TABLE it_pdfdata LINES pdf_itab_size.

  • Text in the mail.

it_mailtxt-line = 'ORDER ACKNOWLEDGEMENT'.

APPEND it_mailtxt.

it_mailtxt-line = ' This is a test mail, Line Number--1'.

APPEND it_mailtxt.

it_mailtxt-line = ' This is a test mail, Line Number--2' &

' This is a test mail, Line Number--2'.

APPEND it_mailtxt.

it_mailtxt-line = ' This is a test mail, Line Number--3' &

' This is a test mail, Line Number--3' &

' This is a test mail, Line Number--3'.

APPEND it_mailtxt.

it_mailtxt-line = ' This is a test mail, Line Number--4' &

' This is a test mail, Line Number--4' &

' This is a test mail, Line Number--4' &

' This is a test mail, Line Number--4'.

APPEND it_mailtxt.

it_mailtxt-line = ' This is a test mail, Line Number--5' &

' This is a test mail, Line Number--5' &

' This is a test mail, Line Number--5' &

' This is a test mail, Line Number--5' &

' This is a test mail, Line Number--5'.

APPEND it_mailtxt.

DESCRIBE TABLE it_mailtxt LINES mailtxt_size.

  • Document Number for Output

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'

EXPORTING

input = vbdka-vbeln

IMPORTING

output = l_vbeln.

  • Attributes of new doc

CONCATENATE 'Order' space 'Acknowledgement' space l_vbeln

INTO it_doc_att-obj_descr SEPARATED BY space.

it_doc_att-sensitivty = 'F'.

it_doc_att-doc_size = mailtxt_size * 255.

  • Create Pack to text in mail body.

CLEAR it_mailpack-transf_bin.

it_mailpack-head_start = 1.

it_mailpack-head_num = 0.

it_mailpack-body_start = 1.

it_mailpack-body_num = mailtxt_size.

it_mailpack-doc_type = 'RAW'.

APPEND it_mailpack.

  • Create Pack to PDF Attach.

it_mailpack-transf_bin = 'X'.

it_mailpack-head_start = 1.

it_mailpack-head_num = 1.

it_mailpack-body_start = 1.

it_mailpack-body_num = pdf_itab_size.

it_mailpack-doc_type = 'PDF'.

CONCATENATE l_vbeln '.pdf' INTO it_mailpack-obj_name.

CONCATENATE 'Order Ack' space l_vbeln INTO it_mailpack-obj_descr.

it_mailpack-doc_size = pdf_itab_size * 255.

APPEND it_mailpack.

*Get email addresses based on Sales document.

SELECT vbeln adrnr INTO TABLE i_vbeln

FROM vbpa

WHERE vbeln = vbdka-vbeln AND

parvw = nast-parvw.

IF NOT i_vbeln[] IS INITIAL.

SELECT addrnumber smtp_addr INTO TABLE i_addrs

FROM adr6 FOR ALL ENTRIES IN i_vbeln

WHERE addrnumber = i_vbeln-adrnr AND

smtp_addr NE space.

ENDIF.

IF i_addrs[] IS NOT INITIAL.

LOOP AT i_addrs.

it_reclist-receiver = i_addrs-smtp_addr.

it_reclist-express = 'X'.

it_reclist-rec_type = 'U'.

it_reclist-notif_del = 'X'. " request delivery notification

it_reclist-notif_ndel = 'X'. " request not delivered notification

APPEND it_reclist.

CLEAR: i_addrs.

ENDLOOP.

ENDIF.

  • Call FM to send email

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

document_data = it_doc_att

put_in_outbox = 'X'

TABLES

packing_list = it_mailpack

object_header = it_mailhead

contents_txt = it_mailtxt

contents_hex = it_pdfdata

receivers = it_reclist

EXCEPTIONS

too_many_receivers = 1

document_not_sent = 2

document_type_not_exist = 3

operation_no_authorizationfiltered= 4

parameter_error = 5

x_error = 6

enqueue_error = 7

OTHERS = 8.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

ENDFORM. " MAIL_OBJECT

Regards,

Ajith

2 REPLIES 2

former_member223537
Active Contributor
0 Kudos

Hi Ajith !!

Please refer this link :

http://www.sapdevelopment.co.uk/reporting/rep_spooltopdf.htm

Here a spool output is converted into PDF and then sent as an email.

I think instead of using FM to change the width, try the logic mentioned in the link.

Also instead of FM CONVERT_TO_OTF use :

1. CONVERT_OTFSPOOLJOB_2_PDF

I hope this should solve the problem.

I had referred the same program from the link and it worked absolutely fine. Also check the adobe acrobat version, i guess old version doesnt support SAP, though not very sure.

Best regards,

Prashant

Former Member
0 Kudos

hi

i am also facing the same problem

i cannot open the pdf file.

it shows an error as " The file has been damaged or corrupted or not correctly decoded"

please help to resolve.