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

Error opening smartform PDF attachement

Former Member
0 Likes
2,640

I get the below error message when trying to open the PDF smartform attachment I've created (both in SOST and in personal e-mail inbox).

'Adobe could not open 'filename' because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachement and wasn't correctly decoded).'

I can see the PDF logo so it's definitely a PDF attachement, so the issue must be the latter.

I seem to have done the necessasry conversions and when I do a preview the data is all there on the PDF and opens using FM 'SSFCOMP_PDF_PREVIEW' which makes it even more strange.

Code below if it helps. I've also reviewed other posts and can't see anything I'm missing in the creation. I have Adobe 7 so that should be sufficient. Any help would be great. Thanks

    DATA i_otfdata TYPE tsfotf,          " Smart Forms: Table OTF
          i_tline TYPE TABLE OF tline WITH HEADER LINE,
          i_receivers TYPE TABLE OF somlreci1 WITH HEADER LINE,
          i_record LIKE solisti1 OCCURS 0 WITH HEADER LINE,
          i_objpack LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
          i_objtxt LIKE solisti1 OCCURS 0 WITH HEADER LINE,
          i_objbin LIKE solisti1 OCCURS 0 WITH HEADER LINE,
          i_reclist LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
          w_mailaddr TYPE ppfdmailad,
          w_mailtype TYPE so_escape,
          w_mailrecipient TYPE swotobjid,
          w_control TYPE ssfctrlop,
          w_compop TYPE ssfcompop,
          w_return TYPE ssfcrescl,
          wa_doc_chng TYPE sodocchgi1,
          w_data TYPE sodocchgi1,
          wa_buffer TYPE string, "To convert from 132 to 255
          wa_objhead TYPE soli_tab,
          v_form_name TYPE rs38l_fnam,
          v_len_in LIKE sood-objlen,
          v_len_out LIKE sood-objlen,
          v_len_outn TYPE i,
          v_lines_txt TYPE i,
          v_lines_bin TYPE i,
          lc_fm TYPE rs38l_fnam,      "local variable to store the
        l_i_document_output_info TYPE ssfcrespd,
        l_i_struc_job_output_info TYPE ssfcrescl,
        l_i_struc_job_output_options TYPE ssfcrescl,
        i_lines TYPE TABLE OF tline WITH HEADER LINE,
        lv_job_output_info      TYPE ssfcrescl,
        lv_document_output_info TYPE ssfcrespd,
        lv_job_output_options  TYPE ssfcresop,
        lv_bin_filesize        LIKE sood-objlen,
        lv_pdf_file TYPE xstring,
        lt_bin_data(255) TYPE x OCCURS 0.

  i_otfdata[] = ls_output_data-otfdata[].

  CALL FUNCTION 'CONVERT_OTF'
    EXPORTING
      format                = 'PDF'
      max_linewidth        = 132
    IMPORTING
      bin_filesize          = lv_bin_filesize
      bin_file              = lv_pdf_file
    TABLES
      otf                  = i_otfdata
      lines                = i_lines
    EXCEPTIONS
      err_max_linewidth    = 1
      err_format            = 2
      err_conv_not_possible = 3
      err_bad_otf          = 4
      OTHERS                = 5.

* convert to binary table
  CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
    EXPORTING
      buffer    = lv_pdf_file
    TABLES
      binary_tab = lt_bin_data.

  IF sy-subrc <> 0.
* Implement suitable error handling here
  ELSE.
*    CALL FUNCTION 'SSFCOMP_PDF_PREVIEW'
*      EXPORTING
*        i_otf                    = i_otfdata
*      EXCEPTIONS
*        convert_otf_to_pdf_error = 1
*        cntl_error              = 2
*        OTHERS                  = 3.
*    IF sy-subrc <> 0.
** Implement suitable error handling here
*    ENDIF.
  ENDIF.

  DATA: BEGIN OF zlines OCCURS 0,
  tline TYPE char255,
  END OF zlines.


*Change the PDF format from 132 to 255.
  CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'
    EXPORTING
      line_width_dst              = '255'
      transfer_bin                = 'X'
    TABLES
*    content_in                  = i_lines
      content_in                  = lt_bin_data
      content_out                = zlines
    EXCEPTIONS
      err_line_width_src_too_long = 1
      err_line_width_dst_too_long = 2
      err_conv_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.

  DESCRIBE TABLE zlines LINES v_lines_txt.


* Attachment

  REFRESH: i_reclist,
  i_objtxt,
  i_objbin,
  i_objpack.
  CLEAR wa_objhead.
  i_objbin[] = zlines[].

* Create Message Body Title and Description

  i_objtxt = 'test with pdf-Attachment!'.
  APPEND i_objtxt.
  DESCRIBE TABLE i_objtxt LINES v_lines_txt.
  READ TABLE i_objtxt INDEX v_lines_txt.
  wa_doc_chng-obj_name = 'smartform'.
  wa_doc_chng-expiry_dat = sy-datum + 10.
  wa_doc_chng-obj_descr = 'smartform'.
  wa_doc_chng-sensitivty = 'F'.
  wa_doc_chng-doc_size = v_lines_txt * 255.

* Main Text
  CLEAR i_objpack-transf_bin.
  i_objpack-head_start = 1.
*  i_objpack-head_num = 1.
  i_objpack-head_num = 0.
*  i_objpack-body_start = 2.
  i_objpack-body_start = 1.
  i_objpack-body_num = v_lines_txt.
  i_objpack-doc_type = 'RAW'.
  APPEND i_objpack.

* Attachment (pdf-Attachment)

  i_objpack-transf_bin = 'X'.
  i_objpack-head_start = 1.
  i_objpack-head_num = 1.
  i_objpack-body_start = 2.

* I_OBJPACK-DOC_TYPE = 'RAW'.
  DESCRIBE TABLE i_objbin LINES v_lines_bin.
  READ TABLE i_objbin INDEX v_lines_bin.
  i_objpack-doc_size = v_lines_bin * 255 .
*  i_objpack-body_num = v_lines_bin.
  i_objpack-body_num = v_lines_txt.
  i_objpack-doc_type = 'PDF'.
  i_objpack-obj_name = 'smart'.
  i_objpack-obj_descr = 'test'.
  APPEND i_objpack.
  CLEAR i_reclist.
  i_reclist-receiver = 'test@test.com'.
  i_reclist-rec_type = 'U'.
  APPEND i_reclist.

* Send new document with attachments via RFC

  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      document_data              = wa_doc_chng
      put_in_outbox              = 'X'
      commit_work                = 'X'
    TABLES
      packing_list              = i_objpack
      object_header              = wa_objhead
      contents_bin              = i_objbin
      contents_txt              = i_objtxt
      receivers                  = i_reclist
    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.

  IF sy-subrc <> 0.
    WRITE:/ 'Error When Sending the File', sy-subrc.
  ELSE.
    WRITE:/ 'Mail sent'.
  ENDIF.

1 ACCEPTED SOLUTION
Read only

tolga_polat
Active Participant
0 Likes
1,854

Hi Dave,

1 ) Use CL_BCS instead of  SO_NEW_DOCUMENT_ATT_SEND_API1 here example code :http://scn.sap.com/thread/3345900


2 ) If you want to use SO_NEW_DOCUMENT_ATT_SEND_API1, send PDF XSTRING data to CONTENTS_HEX and comment CONTENTS_BIN

I hope this will help


I get the below error message when trying to open the PDF smartform attachment I've created (both in SOST and in personal e-mail inbox).

'Adobe could not open 'filename' because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachement and wasn't correctly decoded).'

I can see the PDF logo so it's definitely a PDF attachement, so the issue must be the latter.

I seem to have done the necessasry conversions and when I do a preview the data is all there on the PDF and opens using FM 'SSFCOMP_PDF_PREVIEW' which makes it even more strange.

Code below if it helps. I've also reviewed other posts and can't see anything I'm missing in the creation. I have Adobe 7 so that should be sufficient. Any help would be great. Thanks

    DATA i_otfdata TYPE tsfotf,          " Smart Forms: Table OTF
          i_tline TYPE TABLE OF tline WITH HEADER LINE,
          i_receivers TYPE TABLE OF somlreci1 WITH HEADER LINE,
          i_record LIKE solisti1 OCCURS 0 WITH HEADER LINE,
          i_objpack LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE,
          i_objtxt LIKE solisti1 OCCURS 0 WITH HEADER LINE,
          i_objbin LIKE solisti1 OCCURS 0 WITH HEADER LINE,
          i_reclist LIKE somlreci1 OCCURS 0 WITH HEADER LINE,
          w_mailaddr TYPE ppfdmailad,
          w_mailtype TYPE so_escape,
          w_mailrecipient TYPE swotobjid,
          w_control TYPE ssfctrlop,
          w_compop TYPE ssfcompop,
          w_return TYPE ssfcrescl,
          wa_doc_chng TYPE sodocchgi1,
          w_data TYPE sodocchgi1,
          wa_buffer TYPE string, "To convert from 132 to 255
          wa_objhead TYPE soli_tab,
          v_form_name TYPE rs38l_fnam,
          v_len_in LIKE sood-objlen,
          v_len_out LIKE sood-objlen,
          v_len_outn TYPE i,
          v_lines_txt TYPE i,
          v_lines_bin TYPE i,
          lc_fm TYPE rs38l_fnam,      "local variable to store the
        l_i_document_output_info TYPE ssfcrespd,
        l_i_struc_job_output_info TYPE ssfcrescl,
        l_i_struc_job_output_options TYPE ssfcrescl,
        i_lines TYPE TABLE OF tline WITH HEADER LINE,
        lv_job_output_info      TYPE ssfcrescl,
        lv_document_output_info TYPE ssfcrespd,
        lv_job_output_options  TYPE ssfcresop,
        lv_bin_filesize        LIKE sood-objlen,
        lv_pdf_file TYPE xstring,
        lt_bin_data(255) TYPE x OCCURS 0.

  i_otfdata[] = ls_output_data-otfdata[].

  CALL FUNCTION 'CONVERT_OTF'
    EXPORTING
      format                = 'PDF'
      max_linewidth        = 132
    IMPORTING
      bin_filesize          = lv_bin_filesize
      bin_file              = lv_pdf_file
    TABLES
      otf                  = i_otfdata
      lines                = i_lines
    EXCEPTIONS
      err_max_linewidth    = 1
      err_format            = 2
      err_conv_not_possible = 3
      err_bad_otf          = 4
      OTHERS                = 5.

* convert to binary table
  CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
    EXPORTING
      buffer    = lv_pdf_file
    TABLES
      binary_tab = lt_bin_data.

  IF sy-subrc <> 0.
* Implement suitable error handling here
  ELSE.
*    CALL FUNCTION 'SSFCOMP_PDF_PREVIEW'
*      EXPORTING
*        i_otf                    = i_otfdata
*      EXCEPTIONS
*        convert_otf_to_pdf_error = 1
*        cntl_error              = 2
*        OTHERS                  = 3.
*    IF sy-subrc <> 0.
** Implement suitable error handling here
*    ENDIF.
  ENDIF.

  DATA: BEGIN OF zlines OCCURS 0,
  tline TYPE char255,
  END OF zlines.


*Change the PDF format from 132 to 255.
  CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'
    EXPORTING
      line_width_dst              = '255'
      transfer_bin                = 'X'
    TABLES
*    content_in                  = i_lines
      content_in                  = lt_bin_data
      content_out                = zlines
    EXCEPTIONS
      err_line_width_src_too_long = 1
      err_line_width_dst_too_long = 2
      err_conv_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.

  DESCRIBE TABLE zlines LINES v_lines_txt.


* Attachment

  REFRESH: i_reclist,
  i_objtxt,
  i_objbin,
  i_objpack.
  CLEAR wa_objhead.
  i_objbin[] = zlines[].

* Create Message Body Title and Description

  i_objtxt = 'test with pdf-Attachment!'.
  APPEND i_objtxt.
  DESCRIBE TABLE i_objtxt LINES v_lines_txt.
  READ TABLE i_objtxt INDEX v_lines_txt.
  wa_doc_chng-obj_name = 'smartform'.
  wa_doc_chng-expiry_dat = sy-datum + 10.
  wa_doc_chng-obj_descr = 'smartform'.
  wa_doc_chng-sensitivty = 'F'.
  wa_doc_chng-doc_size = v_lines_txt * 255.

* Main Text
  CLEAR i_objpack-transf_bin.
  i_objpack-head_start = 1.
*  i_objpack-head_num = 1.
  i_objpack-head_num = 0.
*  i_objpack-body_start = 2.
  i_objpack-body_start = 1.
  i_objpack-body_num = v_lines_txt.
  i_objpack-doc_type = 'RAW'.
  APPEND i_objpack.

* Attachment (pdf-Attachment)

  i_objpack-transf_bin = 'X'.
  i_objpack-head_start = 1.
  i_objpack-head_num = 1.
  i_objpack-body_start = 2.

* I_OBJPACK-DOC_TYPE = 'RAW'.
  DESCRIBE TABLE i_objbin LINES v_lines_bin.
  READ TABLE i_objbin INDEX v_lines_bin.
  i_objpack-doc_size = v_lines_bin * 255 .
*  i_objpack-body_num = v_lines_bin.
  i_objpack-body_num = v_lines_txt.
  i_objpack-doc_type = 'PDF'.
  i_objpack-obj_name = 'smart'.
  i_objpack-obj_descr = 'test'.
  APPEND i_objpack.
  CLEAR i_reclist.
  i_reclist-receiver = 'test@test.com'.
  i_reclist-rec_type = 'U'.
  APPEND i_reclist.

* Send new document with attachments via RFC

  CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
    EXPORTING
      document_data              = wa_doc_chng
      put_in_outbox              = 'X'
      commit_work                = 'X'
    TABLES
      packing_list              = i_objpack
      object_header              = wa_objhead
      contents_bin              = i_objbin
      contents_txt              = i_objtxt
      receivers                  = i_reclist
    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.

  IF sy-subrc <> 0.
    WRITE:/ 'Error When Sending the File', sy-subrc.
  ELSE.
    WRITE:/ 'Mail sent'.
  ENDIF.

4 REPLIES 4
Read only

tolga_polat
Active Participant
0 Likes
1,855

Hi Dave,

1 ) Use CL_BCS instead of  SO_NEW_DOCUMENT_ATT_SEND_API1 here example code :http://scn.sap.com/thread/3345900


2 ) If you want to use SO_NEW_DOCUMENT_ATT_SEND_API1, send PDF XSTRING data to CONTENTS_HEX and comment CONTENTS_BIN

I hope this will help


Read only

Former Member
0 Likes
1,854

Hi Dave,

The code provided seems to hold no bugs.

I believe we had a similar problem which was kind of specific to a system/PC wherein the attachment when viewed via the 'SOST' would give the same error message as mentioned here.The user had no issue opening a PDF file directly from the system though.

We reinstalled the adobe component and it works perfectly now.Please try re-installing the PDF(Adobe) in your machine.

Regards

Byju

Read only

Former Member
0 Likes
1,854

Thank you Tolga, option 1 worked. Will use that class from now on

Read only

0 Likes
1,854

You are wellcome,

CL_BCS has a lot ability, and you can find more document about it in SDN.

Regards

Tolga