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: 

SAPScript to PDF

Former Member
0 Kudos
218

Hi,

my requirement is to send a Sapscript as an PDF attachement along with the email. I have done all required code and most of the part of the code seems to be working fine.

I get a email and i have a PDF attachment and when i try to open the PDF attachement i am getting a error.

Where am i going wrong? I searched the forum and found a post from RICH and copied the code as it is to my program and still the same issue.

Any inputs?

10 REPLIES 10

former_member188685
Active Contributor
0 Kudos
149

>i try to open the PDF attachement i am getting a error.

what is the error.?

0 Kudos
149

The error is

"There was an error processing a page.There was a problem reading this document(135)."

Former Member
0 Kudos
149

Hi

Which fm are u using to convert format from OTF to PDF?

U shoudl use CONVERT_OTF_2_PDF

Max

0 Kudos
149

I am using CONVERT_OTF

CALL FUNCTION 'CONVERT_OTF'
      EXPORTING
        format                = 'PDF'
      IMPORTING
        bin_filesize          = gv_filesize
      TABLES
        otf                   = gt_otfdata
        lines                 = gt_pdfdata
      EXCEPTIONS
        err_max_linewidth     = 1
        err_format            = 2
        err_conv_not_possible = 3
        err_bad_otf           = 4
        OTHERS                = 5.

0 Kudos
149

i used the function moduled you have mentioned still the same issue. Same error message.

0 Kudos
149

This message was moderated.

0 Kudos
149

Hi

I'm using release 46C and acrobat reader 8.0, this si my code and it works fine:

Close Form:

CALL FUNCTION 'CLOSE_FORM'
         TABLES
              OTFDATA                  = T_OTF
         EXCEPTIONS
              UNOPENED                 = 1
              BAD_PAGEFORMAT_FOR_PRINT = 2
              SEND_ERROR               = 3
              SPOOL_ERROR              = 4
              OTHERS                   = 5.
    IF SY-SUBRC <> 0.
      MESSAGE I208(00) WITH 'Errore chiusura stampa'(A02).
    ELSE.
      PERFORM DOWNLOAD_PDF.
      PERFORM SEND_MAIL.
    ENDIF.

FORM DOWNLOAD_PDF.

  DATA: BIN_FILESIZE TYPE I.

  DATA: T_FILE_PDF     TYPE STANDARD TABLE OF TLINE,
        DOCTAB_ARCHIVE TYPE STANDARD TABLE OF  DOCS.

  DATA: FILE_TABLE     TYPE FILETABLE WITH HEADER LINE.

  DATA: RC          TYPE I,
        USER_ACTION TYPE I.

  DATA: TITLE    TYPE STRING,
        FILENAME TYPE STRING.

  CHECK P_PDF = 'X'.

  CALL FUNCTION 'CONVERT_OTF_2_PDF'
       IMPORTING
            BIN_FILESIZE           = BIN_FILESIZE
       TABLES
            OTF                    = T_OTF
            DOCTAB_ARCHIVE         = DOCTAB_ARCHIVE
            LINES                  = T_FILE_PDF
       EXCEPTIONS
            ERR_CONV_NOT_POSSIBLE  = 1
            ERR_OTF_MC_NOENDMARKER = 2
            OTHERS                 = 3.
  IF SY-SUBRC <> 0.
    MESSAGE I208(00) WITH 'Errore conversione PDF'(A03).
    EXIT.
  ENDIF.

  TITLE = 'Creare File'(T02).

  CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG
     EXPORTING
       WINDOW_TITLE            = TITLE
       DEFAULT_EXTENSION       = '*.pdf'
    CHANGING
      FILE_TABLE              = FILE_TABLE[]
      RC                      = RC
      USER_ACTION             = USER_ACTION
    EXCEPTIONS
      FILE_OPEN_DIALOG_FAILED = 1
      CNTL_ERROR              = 2
      ERROR_NO_GUI            = 3
      OTHERS                  = 4
          .
  IF SY-SUBRC <> 0.
    MESSAGE I208(00) WITH 'Errore creazione PDF'(A04).
    EXIT.
  ELSE.
    IF USER_ACTION = 9. EXIT. ENDIF.
    IF RC = 1.
      READ TABLE FILE_TABLE INDEX 1.
    ENDIF.
  ENDIF.

  MOVE FILE_TABLE-FILENAME TO FILENAME.

  CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD
    EXPORTING
       BIN_FILESIZE            = BIN_FILESIZE
       FILENAME                = FILENAME
       FILETYPE                = 'BIN'
    CHANGING
      DATA_TAB                = T_FILE_PDF
    EXCEPTIONS
      FILE_WRITE_ERROR        = 1
      NO_BATCH                = 2
      GUI_REFUSE_FILETRANSFER = 3
      INVALID_TYPE            = 4
      NO_AUTHORITY            = 5
      UNKNOWN_ERROR           = 6
      HEADER_NOT_ALLOWED      = 7
      SEPARATOR_NOT_ALLOWED   = 8
      FILESIZE_NOT_ALLOWED    = 9
      HEADER_TOO_LONG         = 10
      DP_ERROR_CREATE         = 11
      DP_ERROR_SEND           = 12
      DP_ERROR_WRITE          = 13
      UNKNOWN_DP_ERROR        = 14
      ACCESS_DENIED           = 15
      DP_OUT_OF_MEMORY        = 16
      DISK_FULL               = 17
      DP_TIMEOUT              = 18
      FILE_NOT_FOUND          = 19
      DATAPROVIDER_EXCEPTION  = 20
      CONTROL_FLUSH_ERROR     = 21
      OTHERS                  = 22
          .
  IF SY-SUBRC <> 0.
    MESSAGE I208(00) WITH 'Errore creazione PDF'(A04).
    EXIT.
  ELSE.
    MESSAGE S208(00) WITH 'File creato con successo'(S01).
  ENDIF.

  CHECK P_OPEN = 'X'.

  CALL FUNCTION 'CALL_BROWSER'
       EXPORTING
            URL                    = FILE_TABLE-FILENAME
       EXCEPTIONS
            FRONTEND_NOT_SUPPORTED = 1
            FRONTEND_ERROR         = 2
            PROG_NOT_FOUND         = 3
            NO_BATCH               = 4
            UNSPECIFIED_ERROR      = 5
            OTHERS                 = 6.

  IF SY-SUBRC <> 0.
    MESSAGE S208(00) WITH 'Impossibile aprire file'(A05).
  ENDIF.

ENDFORM.                    " DOWNLOAD_PDF

U can create an attachement using OPEN_FORM:

IF _OPEN_FORM = SPACE.


      CASE 'X'.
        WHEN P_PRT.
          XDEVICE        = 'PRINTER'.
        WHEN P_PDF.
          XDEVICE        = 'PRINTER'.
          ITCPO-TDGETOTF = 'X'.
        WHEN P_MAIL.

          XPROGRAMM = SY-REPID.


          CALL FUNCTION 'ADDR_GET_NEXT_COMM_TYPE'
               EXPORTING
                    STRATEGY           = 'CS01'
                    ADDRESS_NUMBER     = T_KNA1-ADRNR
               IMPORTING
                    COMM_TYPE          = LVS_COMM_TYPE
                    COMM_VALUES        = LVS_COMM_VALUES
               EXCEPTIONS
                    ADDRESS_NOT_EXIST  = 1
                    PERSON_NOT_EXIST   = 2
                    NO_COMM_TYPE_FOUND = 3
                    INTERNAL_ERROR     = 4
                    PARAMETER_ERROR    = 5
                    OTHERS             = 6.

          IF SY-SUBRC <> 0.
            MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                   WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
          ENDIF.


          CALL FUNCTION 'CONVERT_COMM_TYPE_DATA'
               EXPORTING
                    PI_COMM_TYPE              = LVS_COMM_TYPE
                    PI_COMM_VALUES            = LVS_COMM_VALUES
                    PI_COUNTRY                = T_KNA1-LAND1
                    PI_REPID                  = XPROGRAMM
               IMPORTING
                    PE_ITCPO                  = ITCPO
                    PE_DEVICE                 = XDEVICE
                    PE_MAIL_RECIPIENT         = LVS_RECIPIENT
                    PE_MAIL_SENDER            = LVS_SENDER
               EXCEPTIONS
                    COMM_TYPE_NOT_SUPPORTED   = 1
                    RECIPIENT_CREATION_FAILED = 2
                    SENDER_CREATION_FAILED    = 3
                    OTHERS                    = 4.

          IF SY-SUBRC <> 0.
            MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
          ENDIF.


      ENDCASE.


      CALL FUNCTION 'OPEN_FORM'
           EXPORTING
                DEVICE                      = XDEVICE
                DIALOG                      = 'X'
                FORM                        = 'ZFI_CL_EC_MOVI'
                OPTIONS                     = ITCPO
                MAIL_SENDER                 = LVS_SENDER
                MAIL_RECIPIENT              = LVS_RECIPIENT
           EXCEPTIONS
                CANCELED                    = 1
                DEVICE                      = 2
                FORM                        = 3
                OPTIONS                     = 4
                UNCLOSED                    = 5
                MAIL_OPTIONS                = 6
                ARCHIVE_ERROR               = 7
                INVALID_FAX_NUMBER          = 8
                MORE_PARAMS_NEEDED_IN_BATCH = 9
                SPOOL_ERROR                 = 10
                OTHERS                      = 11.
      IF SY-SUBRC <> 0.
        EXIT.
      ENDIF.

      _OPEN_FORM = 'X'.

Max

0 Kudos
149

Hi Thanks again.

But i noticed a strange issue. I copied the downlod code and i noticed that i am able to downlowd the PDF and open the PDF with no issues.

But if i remove the downloc code and use the email sending logic then i am getting a PDF attachment which i am unable to open and i am getting the same error message.

So i can conclude that the problem is with the sending the email with attachement and not with the OTF to PDF conversion. Any idea what may be wrong in the email?

0 Kudos
149

Hi

After converting OTF to PDF format u elaborate the PDF data before sending the mail?

Max

0 Kudos
149

I am having the same issue described in this thread.....I am on ECC 6.0 and am converting SAPScript (OTF) to PDF. I then send via SO_OBJECT_SEND. The PDF views fine right from trxn SOST but when I send the email out and click on the PDF attachment in Outlook, I get

the following error: 'Adobe Reader could not open <file> because it is either not a supported

file type or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly decoded).'

Here's my code:

CALL FUNCTION 'CLOSE_FORM'

TABLES

otfdata = l_otfdata_tab

EXCEPTIONS

OTHERS = 1.

CALL FUNCTION 'CONVERT_OTF'

EXPORTING

FORMAT = 'PDF'

MAX_LINEWIDTH = 134

  • ARCHIVE_INDEX = ' '

  • COPYNUMBER = 0

  • ASCII_BIDI_VIS2LOG = ' '

  • PDF_DELETE_OTFTAB = ' '

IMPORTING

BIN_FILESIZE = l_binsize

  • BIN_FILE =

TABLES

OTF = l_otfdata_tab

LINES = l_otfdata_tab1

EXCEPTIONS

ERR_MAX_LINEWIDTH = 1

ERR_FORMAT = 2

ERR_CONV_NOT_POSSIBLE = 3

ERR_BAD_OTF = 4

OTHERS = 5

.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

CALL FUNCTION 'QCE1_CONVERT'

TABLES

t_source_tab = l_otfdata_tab1

t_target_tab = l_objbin

EXCEPTIONS

convert_not_possible = 1

OTHERS = 2.

  • Add the Email Body to MAIL_CONTENT table

MOVE 'Thank you for your order' TO mail_content-line.

APPEND mail_content.

MOVE 'See attached PDF for your Order Confirmation' TO mail_content-line.

APPEND mail_content.

packing_list-transf_bin = 'X'.

packing_list-head_start = 1.

packing_list-head_num = 2.

packing_list-body_start = 1.

DESCRIBE TABLE l_objbin[] LINES packing_list-body_num.

packing_list-body_num = 9999.

packing_list-objtp = 'PDF'.

packing_list-objnam = 'Order Confirmation'.

packing_list-OBJDES = 'Order Confirmation'.

  • packing_list-file_ext = 'PDF'.

APPEND packing_list.

CLEAR packing_list

CALL FUNCTION 'SO_OBJECT_SEND'

EXPORTING

object_hd_change = tsood1

object_type = 'RAW'

TABLES

objcont = mail_content

  • objcont = l_objbin

receivers = receivers

att_cont = l_objbin

packing_list = packing_list

  • note_text = mail_content

EXCEPTIONS

active_user_not_exist = 1

communication_failure = 2

component_not_available = 3

folder_not_exist = 4

folder_no_authorization = 5

forwarder_not_exist = 6

note_not_exist = 7

object_not_exist = 8

object_not_sent = 9

object_no_authorization = 10

object_type_not_exist = 11

operation_no_authorization = 12

owner_not_exist = 13

parameter_error = 14

substitute_not_active = 15

substitute_not_defined = 16

system_failure = 17

too_much_receivers = 18

user_not_exist = 19

x_error = 20

originator_not_exist = 21

OTHERS = 22.