Application Development and Automation 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: 
Read only

Problems when sending PDF attachments....

luis_rod
Participant
0 Likes
2,092

Hi all:

First, let me apologize beforehand, as my ABAP knowledge is self-taught, and I’m pretty sure I must be doing a lot of mistakes. Also, part of the code I’m using is adapted from some examples I have found online, and undoubtedly I must have interpreted those lines in a wrong way.

I have a program that creates several files (attachments) to be sent by a single email. Most of them are .CSV, and those are sent (and received) perfectly. Nevertheless, when trying to open the .PDF attachments I get an error message that states that Adobe could not open the file “because it is either not a supported file type or because the file has been damaged”.

In my test program, the spool is created using the output created by an ALV program that executes in the background. The relevant code sections are as follow:

   CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
EXPORTING
src_spoolid = pv_spool
no_dialog = ' '
dst_device = 'LOCL'
IMPORTING
pdf_bytecount = pdf_bytecount
TABLES
pdf = lt_pdf-SPAN { font-family: "Courier New"; font-size: 12pt; color: #000000; background: #FFFFFF; }.L0S33 { color: #4DA619; }.L0S52 { color: #0000FF; }.L0S55 { color: #800080; }

After that, I convert lt_pdf to a single string:

CLEAR gv_buffer.
LOOP AT lt_pdf.
CONCATENATE gv_buffer lt_pdf INTO gv_buffer.
ENDLOOP. SPAN { font-family: "Courier New"; font-size: 12pt; color: #000000; background: #FFFFFF; }.L0S52 { color: #0000FF; }.L0S55 { color: #800080; }

And add the attachment to my email:


    TRY.
cl_bcs_convert=>string_to_solix(
EXPORTING
iv_string = gv_buffer
iv_codepage = ' '
iv_add_bom = 'X'
IMPORTING
et_solix = binary_content
ev_size = size ).
CATCH cx_bcs.
MESSAGE e445(so).
ENDTRY.
lv_name = w_string.
document->add_attachment(
i_attachment_type = 'pdf'
i_attachment_subject = lv_name
i_attachment_size = size
i_att_content_hex = binary_content ).
send_request->set_document( document ). SPAN { font-family: "Courier New"; font-size: 12pt; color: #000000; background: #FFFFFF; }.L0S33 { color: #4DA619; }.L0S52 { color: #0000FF; }.L0S55 { color: #800080; }.L0S70 { color: #808080; }

But, as stated before, this is not working.


Any ideas?


TIA,

Luis

3 REPLIES 3
Read only

abo
Active Contributor
1,963

Most of the time, when this issue occurs it is due to a wrong size parameter, which is either omitted or incorrectly derived. This is where I'd concentrate my attention. In the forums and in the blogs you can find complete functioning examples

Also, please remember to switch back to display mode when copying code from the GUI: this will avoide the html noise, like "span" and similar.

Read only

luis_rod
Participant
1,963

Andrea,

Thanks for your answer. Will check further the size info, although I'm afraid I have tried several approaches without success. The routine I have been using was found, precisely, in the community forums.

Thanks for the tip for avoiding the HTML code.


Regards,

Luis

Read only

luis_rod
Participant
1,963

Rewrote both, the size determination and the send code, and now it works.

Thanks to Andrea for steering me in the right direction.