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: 

How to ZIP a PDF file email attachment

Former Member
0 Kudos

Hi,

We have an ABAP report requirement to send an email to a user. This program will send an email with PDF attachement. However, the PDF attachment is quite big (9MB) and our email server couldn't handle it (5MB only). Is there any way to ZIP this PDF file attachment?

I am using a SAP release 4.6C with OS WinNT. And the ABAP program should be able to run in Foreground/Background.

Thanks for your help in advance...

Kind regards,

Herson

1 ACCEPTED SOLUTION

FredericGirod
Active Contributor
0 Kudos

Hi Heherson,

maybe have a look to the class : CL_ABAP_GZIP_BINARY_STREAM ...

Good luck

Frédéric

18 REPLIES 18

FredericGirod
Active Contributor
0 Kudos

Hi Heherson,

maybe have a look to the class : CL_ABAP_GZIP_BINARY_STREAM ...

Good luck

Frédéric

0 Kudos

Read this post:

I hope this will be helpful.

0 Kudos

Hi Sudheer,

This gives me more info to what I'm doing now. But I'm still lacking something to make this work perfectly.

My program converts the smartform spool into OTF format and then to PDF file format. The PDF file is still stored in an internal table. Currently my program attached this PDF file (in internal table) to an email but as I've said it is quite big. From the thread it attaches a zip file already from application server. Do you have any idea how to ZIP a file from application server?

Thanks again for your help...

Kind regards,

Herson

0 Kudos

Hi,

Try the function module TABLE_COMPRESS, before emailing.

Regards,

Suresh Datti

0 Kudos

Use the GZip library: CL_ABAP_GZIP

0 Kudos

Hi Suresh,

I tried using the TABLE_COMPRESS function prior to sending the email but SAP wasn't able to convert the attachment, thus, it will result to an error.

Thanks for your help...

Thanks,

Herson

0 Kudos

Hi Wenceslaus,

Are this class library also available in Release 4.6C?

Kind regards,

Herson

0 Kudos

Hi Heherson,

I have the same requirement. I am converting the ABAP Spool to PDF and then seding as mail attachment. My report output is too big that it is creating the PDF of 57MB. So i want to zip this PDF before sending as a mail attachement.

I saw that you had a same requirement. Did you get any solution to this. Can you please share it with me if you have any solution or work around for this?

Thanks,

RS

0 Kudos

Hi all,

I think the GZIP classes are not available with 4.6C. You may write the PDF data to a binary file on the server, call a unix GZIP, read and mail as attachment.

Regards,

Clemens

0 Kudos

Hi Clemens,

I am working in ECC 6.0 and these classes are available here. Can you help me finding the solution?

Thanks,

RS

0 Kudos

Hi RS,

Sorry I haven't got the time to figure out the details. But Please be warned: PDF format already uses some kind of compression technique. So if you ZIP a pdf file, the size will shrink not more than 5 or 10 percent.

And this may be still too much for you. PDF is not pure text where you can easily gain 90 percent.

Sometimes it is better to start at the root: What are the contents of the PDF and why is it so big?

Regards,

Clemens

0 Kudos

Hi Clemens,

The PDF is spool ouput. I have a report which sometime generate a output as big as 3500 pages and i have to send it as PDF. When i am converting this spool to PDF, it is 57MB which is fine in SAP but too big for mail exchange server.

You mentioned that eventhough i will be able compress the PDF it won't be suffecient. But when i download that PDF (57MB) to PC and ZIP is using WinZip the file was only 3 MB and i was easily able to send it across.

So, now i want to try SAP ZIP functionality (class CL_ABAP_ZIP). I tried to play around with this class yesterday and able to produce a ZIP file (not a big output though, i just created a test program of 1 page output). I was able to send the file in mail and successfully able to unzip it. But when i try of open the PDF file which i had zipped, i got the message that file is corrupted and i was not able to open it.

Can you help me with this ZIP conversion?

Thanks,

RS

0 Kudos

Hi Heherson/Rs

I have done the same required long time back. My requirement was to compare the differences between the multiple tables stored in different systems thorough RFC calls . Then if differences found then mail or notify about the same to the chosen person(selection screen).

In order to achieve this requirement I followed the below given solution.

1) Send mail with PDF attachment if records are less then or equal to 300 (This makes PDF size less then 5 MB).

2) If records are more then 300 then a mail goes to the chosen person with out PDF attachment and mail's body describes about the differences like number of differences and also it tells the user to Check the given spool number.

Please let me Know if this serves your purpose or not.

Here Zip will also not work because it not certain that zip file size full fills mail server size.

0 Kudos

Read Notes:

616958

644640

You can create a class method:

CALL METHOD zca_tools=>zip_table

EXPORTING

i_data_table = <data_struc>

i_filename = 'aa'

IMPORTING

e_bin_table = t_zipped

e_bin_length = lines.

*----


METHOD zip_table.

DATA: lv_original_length(10) TYPE n,

lv_data_ref TYPE REF TO data,

lv_struc_ref TYPE REF TO data.

DATA: lv_zip TYPE REF TO cl_abap_zip,

lv_lines TYPE i,

lv_length TYPE i,

lv_data_to_zip TYPE xstring,

lv_zip_file TYPE xstring,

lv_catch TYPE REF TO cx_root,

lv_message TYPE string.

FIELD-SYMBOLS: <data_struc> TYPE ANY,

<final_data> TYPE ANY,

<final_data_table> TYPE STANDARD TABLE,

<aux> TYPE x.

LOOP AT i_data_table ASSIGNING <data_struc>.

DESCRIBE FIELD <data_struc> LENGTH lv_original_length IN CHARACTER MODE.

EXIT.

ENDLOOP.

TRY.

CREATE DATA lv_data_ref TYPE c LENGTH lv_original_length.

ASSIGN lv_data_ref->* TO <final_data>.

CREATE DATA lv_data_ref LIKE STANDARD TABLE OF <final_data>.

ASSIGN lv_data_ref->* TO <final_data_table>.

APPEND LINES OF i_data_table TO <final_data_table>.

DESCRIBE TABLE <final_data_table> LINES lv_lines.

ASSIGN COMPONENT 1 OF STRUCTURE <final_data> TO <aux> CASTING.

IF sy-subrc NE 0 OR NOT <aux> IS ASSIGNED.

ASSIGN COMPONENT 0 OF STRUCTURE <final_data> TO <aux> CASTING.

ENDIF.

DESCRIBE FIELD <aux> LENGTH lv_length IN BYTE MODE.

MULTIPLY lv_length BY lv_lines.

CATCH cx_root INTO lv_catch. "#EC CATCH_ALL

lv_message = lv_catch->get_text( ).

MESSAGE lv_message TYPE 'E' RAISING error.

ENDTRY.

CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'

EXPORTING

input_length = lv_length

first_line = 1

last_line = lv_lines

IMPORTING

buffer = lv_data_to_zip

TABLES

binary_tab = <final_data_table>

EXCEPTIONS

failed = 1

OTHERS = 2.

IF sy-subrc NE 0.

IF sy-msgty IS INITIAL.

sy-msgty = 'S'.

ENDIF.

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

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

ENDIF.

CREATE OBJECT lv_zip.

CALL METHOD lv_zip->add

EXPORTING

name = i_filename

content = lv_data_to_zip.

CALL METHOD lv_zip->save

RECEIVING

zip = lv_zip_file.

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

EXPORTING

buffer = lv_zip_file

TABLES

binary_tab = e_bin_table.

TRY.

DESCRIBE TABLE e_bin_table LINES lv_lines.

e_bin_length = lv_lines * 255. "255 is the length of each line of e_bin_table

CATCH cx_root INTO lv_catch. "#EC CATCH_ALL

lv_message = lv_catch->get_text( ).

MESSAGE lv_message TYPE 'E' RAISING error.

ENDTRY.

ENDMETHOD.

I hope it helps!

Regards,

Frinee

0 Kudos

hi grus,

if you manage to zip a pdf, it will shrink a lot

you can see an example below.

original pdf is an output of FM: CONVERT_ABAPSPOOLJOB_2_PDF

when i rarred it with winrar,

it dramatically shrinked.

27.07.2010 15:25 6.144.225 AuiditLog_20100727122735.013_X.pdf

27.07.2010 15:26 112.467 AuiditLog_20100727122735.013_X.rar

2 File(s) 6.256.692 bytes

0 Dir(s) 71.033.675.776 bytes free

but i have no answer yet for zipping on the abap side.

0 Kudos

Hi all,

i was able to send me a zip file with the help of this thread.

[http://wiki.sdn.sap.com/wiki/display/ABAP/CL_ABAP_ZIPusage-ZippingABAPreportoutput |http://wiki.sdn.sap.com/wiki/display/ABAP/CL_ABAP_ZIPusage-ZippingABAPreportoutput ]

instead of Gui_Download FM, you should use send mail FM.

you gotta check it out.

abdul_hakim
Active Contributor
0 Kudos

Hi Heherson,

i am in need of a program which send email with PDF attachment.Could you please provide me the code for it..

Many Thanks,

Abdul

0 Kudos

Hi Abdul,

Hope this will help you.... This is mainly the code for attaching a PDF file to an Email.

data: it_pdf like tline occurs 0 with header line.

data: wa_doc_data like sodocchgi1.

data: it_packing_list like sopcklsti1 occurs 0 with

header line,

it_object_header like solisti1 occurs 0 with

header line,

it_contents_txt like solisti1 occurs 0 with

header line,

it_contents_bin like solisti1 occurs 0 with

header line,

it_contents_hex like solix occurs 0 with

header line,

it_contents like solix occurs 0 with

header line,

it_receivers like somlreci1 occurs 0 with

header line.

data: v_line_counter type i.

data: v_buffer type string.

  • prepare attachment

  • Transfer the 132-long strings to 255-long strings

loop at it_pdf.

translate it_pdf using ' ~'.

concatenate v_buffer it_pdf into v_buffer.

endloop.

translate v_buffer using '~ '.

do.

it_contents_bin = v_buffer.

append it_contents_bin.

shift v_buffer left by 255 places.

if v_buffer is initial. exit. endif.

enddo.

  • prepare email body (line 1)

it_contents_txt-line = 'Write your message here'.

append it_contents_txt.

describe table it_contents_txt lines v_line_counter.

read table it_contents_txt index v_line_counter.

  • prepare document data

wa_doc_data-obj_name = 'URGENT'.

wa_doc_data-expiry_dat = sy-datum + 10.

wa_doc_data-obj_descr = 'Sales Backorder Report'.

wa_doc_data-sensitivty = 'O'.

wa_doc_data-doc_size = ( v_line_counter - 1 ) *

255 + strlen( it_contents_txt ).

  • prepare packing list

clear it_packing_list-transf_bin.

it_packing_list-head_start = 1.

it_packing_list-head_num = 0.

it_packing_list-body_start = 1.

it_packing_list-body_num = v_line_counter.

it_packing_list-doc_type = 'RAW'.

append it_packing_list.

describe table it_contents_bin lines v_line_counter.

read table it_contents_bin index v_line_counter.

it_packing_list-transf_bin = 'X'.

it_packing_list-head_start = 1.

it_packing_list-head_num = 0.

it_packing_list-body_start = 1.

it_packing_list-body_num = v_line_counter.

it_packing_list-doc_type = 'PDF'.

it_packing_list-obj_name = v_bztxt.

it_packing_list-obj_descr = '%PDF-File.pdf'.

it_packing_list-doc_size = ( v_line_counter - 1 ) *

255 + strlen( it_contents_bin ).

append it_packing_list.

  • prepare receiver's list

it_receivers-receiver = 'email@address.com'.

it_receivers-express = 'X'.

it_receivers-copy = 'X'.

it_receivers-rec_type = 'U'.

it_receivers-notif_del = 'X'.

it_receivers-notif_ndel = 'X'.

append it_receivers.

call function 'SO_NEW_DOCUMENT_ATT_SEND_API1'

exporting

document_data = wa_doc_data

put_in_outbox = 'X'

tables

packing_list = it_packing_list

object_header = it_object_header

contents_bin = it_contents_bin

contents_txt = it_contents_txt

receivers = it_receivers

exceptions

too_many_receivers = 1

document_not_sent = 2

document_type_not_exist = 3

operation_no_authorization = 4

parameter_error = 5

x_error = 6

enqueue_error = 7

others = 8.