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

Smartform to PDF Conversion

Former Member
0 Kudos
2,875

Hi All,

I am using the following FM to convert my smartform output to PDF and to Send mail.

CONVERT_OTF_2_PDF

SO_NEW_DOCUMENT_ATT_SEND_API1

everything is fine. But Logo is not been displayed in PDF. when i try to open the PDF, displaying the message 'error when trying to parse the image file'.

Remember i am not generating any spool request in my smartform. can anybody help me.

Thanks in advance.

12 REPLIES 12
Read only

Former Member
0 Kudos
1,217

Hi

What are you converting if you are nnot generating a spool?

Max

Read only

0 Kudos
1,217

we can convert the smart form to PDF without generating the spool, here is the sample code

1. call the smart form FM

call function '/xxx/xxxx'

EXPORTING

user_settings = space

control_parameters = control_parameters

output_options = output_options

IMPORTING

job_output_info = output_data

TABLES

zsystems = lt_sys

EXCEPTIONS

formatting_error = 1

internal_error = 2

send_error = 3

user_canceled = 4

others = 5.

2. convert the OTF data to PDF

call function 'CONVERT_OTF'

EXPORTING

format = 'PDF'

IMPORTING

bin_filesize = l_pdf_len

bin_file = l_pdf_xstring

TABLES

OTF = OUTPUT_DATA-OTFDATA

LINES = LT_LINES

EXCEPTIONS

err_max_linewidth = 1

err_format = 2

err_conv_not_possible = 3

err_bad_otf = 4

others = 5.

Regards

Raja

Read only

0 Kudos
1,217

Hi Raja,

Thanks. I have exactly followed the same steps. I am getting the mail also. Only thing is when i am opending the PDF attachment in the mail, Adobe is displaying the messae 'There was an error when trying to parse image file' and logo is not displayed

Read only

ferry_lianto
Active Contributor
0 Kudos
1,217

Hi Rajeswara,

Please check this thread for sample code and solution.

Hope this will help.

Regards,

Ferry Lianto

Read only

Former Member
0 Kudos
1,217

Hi,

To Convert SmartForm output to PDF and send it as Mail attachment

Step 1: To convert SmartForm output to PDF

Smart Forms does not support direct output in PDF format. Instead, the OTF output has to be converted to PDF. The function module generated by the SmartForm has to be supplied with Control Structure parameters that will export the SmartForm output to OTF format. The Output Text Format (OTF) is the established SAP output format for printing forms. It consists of a number of simple, device-independent commands, thus allowing output to be directed to different output devices such as line printers and laser printers, or as an on-screen print preview. OTF is an explicit output format, which means that once SAP Smart Forms has generated an OTF output, no modifications can be made.

OTF:

OTF is not a document; it is a format in which data becomes available after it is templated by a Script or Smartform. The SmartForm takes the data you have passed to it, formats it according to the output settings, layout, page size, styles etc. and then forwards it to it's intended destination which is normally a print device. Since SmartForm output is not necessarily targeted at print output, R/3 allows you to alternatively collect the formatted results of the SmartForm(or SAPScript) and use this data for other purposes, like creating a DOC(MS Word) file, create a PDF file, send mail etc. The standard format used after generation and formatting of SmartForm output is known as OTF.

The procedure for the form to be returned as a table in OTF format is as follows:

1. Define a structure of type SSFCTRLOP (control structure, standard parameter CONTROL_PARAMETERS) and another structure of type SSFCRESCL (to contain the output results, standard parameter JOB_OUTPUT_INFO):

DATA: my_control_pars TYPE ssfctrlop. "For CONTROL_PARAMETERS

DATA: my_output_info TYPE ssfcrescl. "For JOB_OUTPUT_INFO

2. To deactivate the dialogs and to inform SAP Smart Forms that you only want the OTF table to be returned, set the parameters NO_DIALOG and GETOTF of the control structure:

my_control_pars-no_dialog = 'X'.

my_control_pars-getotf = 'X'.

3. Pass both structures in the call of the generated function module.

Now access the OTF table in the formal parameter JOB_OUTPUT_INFO using the OTFDATA parameter of your structure.

4. Get the OTF output from table OTFDATA of the standard parameter JOB_OUTPUT_INFO.

5. To convert the OTF output to PDF, transfer the OTF table to the function module CONVERT_OTF. To do this, set the parameter FORMAT to 'PDF'. The output can be returned either as a binary string (parameter BIN_FILE) or as a character table (parameter LINES). SAP recommends the first variant.

You can then store the PDF output using the function module GUI_DOWNLOAD, for example, as a local file on your PC.

Function Module : Convert_OTF

CALL FUNCTION "CONVERT_OTF"
       EXPORTING    FORMAT                = "PDF"
       IMPORTING    BIN_FILESIZE          = FILE_LEN
       TABLES       OTF                   = OTFDATA
                    LINES                 = PDFDATA
      EXCEPTIONS  
                  ERR_MAX_LINEWIDTH =1                        
                    ERR_FORMAT            = 2
                    ERR_CONV_NOT_POSSIBLE = 3
                    OTHERS                = 4.

Step 2: Sending PDF document as an attachment by mail.

You have to create variables/structure/table of the following type.

1) Data of an object which can be changed.

2) Description of Imported Object Components.

3) Single List with Column Length 255.

4) Structure of the API Recipient List.

When the data is converted into the PDF format from OTF (Function Module Convert_OTF), it is stored in an internal table, which has a similar structure as Text Lines (TLINE). Let this internal table name be LT_PDFDATA. Hence any operation that is to be performed on the data, this table is taken into consideration.

Following steps have to be followed to send the PDF as an attachment.

1) Conversion of the content in LT_PDFDATA in binary format.

The table LT_PDFDATA has two columns. Convert the entire table into a single line and replace all the space with a special character (say ~).

Then convert the entire string into lines of size 255 characters, and store it in an internal table (OBJBIN).

2) Create Receivers List.

This table will contain the receiver name and receiver type(Internet Address, Remote SAP, etc.).

3) Create Message body, Title, and Description.

4) Create Message Attachment.

Function Module Used :

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
  EXPORTING
    DOCUMENT_DATA                    = DOCDATA
    PUT_IN_OUTBOX                    = 'X'
  TABLES
    PACKING_LIST                     = OBJPACK
    OBJECT_HEADER                    = OBJHEAD
    CONTENTS_BIN                     = OBJBIN
    CONTENTS_TXT                     = OBJTXT
    RECEIVERS                        = RECLIST.

Regards,

Gayathri

Read only

0 Kudos
1,217

Hi Gayatri,

Thanks. I have exactly followed the same steps. I am getting the mail also. Only thing is when i am opending the PDF attachment in the mail, Adobe is displaying the messae 'There was an error when trying to parse image file' and logo is not displayed.

Read only

0 Kudos
1,217

Hello Gayathri,

I also have done in the same way. I am getting the email with PDF attachment but when i try to open the PDF i am getting error as "Adobe reader couldn't open the filename.PDF because it is either not a supported file type or because the file has been damaged(for example, it was sent an email attachment and wasn't cvorrectly decoded)"

Can you pls advice me if i am doing something wrong.

Thanks,

Sunil

Read only

0 Kudos
1,217

Hi Sunil,

I had just implemented smartforms myself. I am not sure if you have solved this problem. But anyway just to share my experience for this problem.

1. Check your font type in font type. If you are trying to use different font style other than Times new roman, you will hit this error. I am not sure if you will be able to set the printer device to support beyond te Times New Roman.

2. Check to make sure that your smartforms is set to 'Standard' in the layout. You can access this via t-code: PHAP_CATALOG_PA. If you set it to XSF or other settings, you will have this error.

3. Check that your graphic is appearing correctly in the Smartforms. This is to eliminate the error caused by graphic.

When this error appears, it could be caused by the above issues. But there might be more which I might not have encountered. The error is caused as there are 0 data. If you look into the file size of the PDF you created, you will find that it is 0 byte.

Read only

0 Kudos
1,217

Yo tengo el mismo problema, cuando envio un pdf como adjunto en un e-mail y contiene logos o graficos, este no se puede abrir por el destinatario. Alguien puede ayudarme GRACIAS.

Eduardo Moreno

prading@gmail.com

Read only

Former Member
0 Kudos
1,217

Hi,

1. After getting output of smartform generate spool.

2. Copy that spool number.

3. Go to SE38 & execute the program RSTXTPDF4 .

4. In that program give spool no & path(where u want that pdf file whether in c or d drive with .pdf format)

If this is helpful please reward points

Read only

Former Member
0 Kudos
1,217

Hai Rajeswara Rao

Check the following Code

REPORT ZRICH_0003.

DATA: ITCPO LIKE ITCPO,

TAB_LINES LIKE SY-TABIX.

  • Variables for EMAIL functionality

DATA: MAILDATA LIKE SODOCCHGI1.

DATA: MAILPACK LIKE SOPCKLSTI1 OCCURS 2 WITH HEADER LINE.

DATA: MAILHEAD LIKE SOLISTI1 OCCURS 1 WITH HEADER LINE.

DATA: MAILBIN LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

DATA: MAILTXT LIKE SOLISTI1 OCCURS 10 WITH HEADER LINE.

DATA: MAILREC LIKE SOMLREC90 OCCURS 0 WITH HEADER LINE.

DATA: SOLISTI1 LIKE SOLISTI1 OCCURS 0 WITH HEADER LINE.

PERFORM SEND_FORM_VIA_EMAIL.

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

  • FORM SEND_FORM_VIA_EMAIL *

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

FORM SEND_FORM_VIA_EMAIL.

CLEAR: MAILDATA, MAILTXT, MAILBIN, MAILPACK, MAILHEAD, MAILREC.

REFRESH: MAILTXT, MAILBIN, MAILPACK, MAILHEAD, MAILREC.

  • Creation of the document to be sent File Name

MAILDATA-OBJ_NAME = 'TEST'.

  • Mail Subject

MAILDATA-OBJ_DESCR = 'Subject'.

  • Mail Contents

MAILTXT-LINE = 'Here is your file'.

APPEND MAILTXT.

  • Prepare Packing List

PERFORM PREPARE_PACKING_LIST.

  • Set recipient - email address here!!!

MAILREC-RECEIVER = 'itsme@whatever.com'.

MAILREC-REC_TYPE = 'U'.

APPEND MAILREC.

  • Sending the document

CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'

EXPORTING

DOCUMENT_DATA = MAILDATA

PUT_IN_OUTBOX = ' '

TABLES

PACKING_LIST = MAILPACK

OBJECT_HEADER = MAILHEAD

CONTENTS_BIN = MAILBIN

CONTENTS_TXT = MAILTXT

RECEIVERS = MAILREC

EXCEPTIONS

TOO_MANY_RECEIVERS = 1

DOCUMENT_NOT_SENT = 2

OPERATION_NO_AUTHORIZATION = 4

OTHERS = 99.

ENDFORM.

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

  • Form PREPARE_PACKING_LIST

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

FORM PREPARE_PACKING_LIST.

CLEAR: MAILPACK, MAILBIN, MAILHEAD.

REFRESH: MAILPACK, MAILBIN, MAILHEAD.

DESCRIBE TABLE MAILTXT LINES TAB_LINES.

READ TABLE MAILTXT INDEX TAB_LINES.

MAILDATA-DOC_SIZE = ( TAB_LINES - 1 ) * 255 + STRLEN( MAILTXT ).

  • Creation of the entry for the compressed document

CLEAR MAILPACK-TRANSF_BIN.

MAILPACK-HEAD_START = 1.

MAILPACK-HEAD_NUM = 0.

MAILPACK-BODY_START = 1.

MAILPACK-BODY_NUM = TAB_LINES.

MAILPACK-DOC_TYPE = 'RAW'.

APPEND MAILPACK.

  • Creation of the document attachment

  • This form gets the OTF code from the SAPscript form.

  • If you already have your OTF code, I believe that you may

  • be able to skip this form. just do the following code, looping thru

  • your SOLISTI1 and updating MAILBIN.

PERFORM GET_OTF_CODE.

LOOP AT SOLISTI1.

MOVE-CORRESPONDING SOLISTI1 TO MAILBIN.

APPEND MAILBIN.

ENDLOOP.

DESCRIBE TABLE MAILBIN LINES TAB_LINES.

MAILHEAD = 'TEST.OTF'.

APPEND MAILHEAD.

    • Creation of the entry for the compressed attachment

MAILPACK-TRANSF_BIN = 'X'.

MAILPACK-HEAD_START = 1.

MAILPACK-HEAD_NUM = 1.

MAILPACK-BODY_START = 1.

MAILPACK-BODY_NUM = TAB_LINES.

MAILPACK-DOC_TYPE = 'OTF'.

MAILPACK-OBJ_NAME = 'TEST'.

MAILPACK-OBJ_DESCR = 'Subject'.

MAILPACK-DOC_SIZE = TAB_LINES * 255.

APPEND MAILPACK.

ENDFORM.

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

  • Form GET_OTF_CODE

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

FORM GET_OTF_CODE.

DATA: BEGIN OF OTF OCCURS 0.

INCLUDE STRUCTURE ITCOO .

DATA: END OF OTF.

DATA: ITCPO LIKE ITCPO.

DATA: ITCPP LIKE ITCPP.

CLEAR ITCPO.

ITCPO-TDGETOTF = 'X'.

  • Start writing OTF code

CALL FUNCTION 'OPEN_FORM'

EXPORTING

FORM = 'ZTEST_FORM'

LANGUAGE = SY-LANGU

OPTIONS = ITCPO

DIALOG = ' '

EXCEPTIONS

OTHERS = 1.

CALL FUNCTION 'START_FORM'

EXCEPTIONS

ERROR_MESSAGE = 01

OTHERS = 02.

CALL FUNCTION 'WRITE_FORM'

EXPORTING

WINDOW = 'MAIN'

EXCEPTIONS

ERROR_MESSAGE = 01

OTHERS = 02.

  • Close up Form and get OTF code

CALL FUNCTION 'END_FORM'

EXCEPTIONS

ERROR_MESSAGE = 01

OTHERS = 02.

MOVE-CORRESPONDING ITCPO TO ITCPP.

CALL FUNCTION 'CLOSE_FORM'

IMPORTING

RESULT = ITCPP

TABLES

OTFDATA = OTF

EXCEPTIONS

OTHERS = 1.

  • Move OTF code to structure SOLI form email

CLEAR SOLISTI1. REFRESH SOLISTI1.

LOOP AT OTF.

SOLISTI1-LINE = OTF.

APPEND SOLISTI1.

ENDLOOP.

ENDFORM.

Thanks & regards

Sreenivasulu P

Read only

Former Member
0 Kudos
1,217

hi ,

Before using Convert_otf_2_pdf use following FMs.

after filling NAST table use READ_OTF_FROM_MEMORY , CONVERT_OTF_2_PDF then use QCE1_CONVERT( Converting pdf data to raw data).

Regards

Ashok P

Message was edited by: Ashok Parupalli