02-15-2007 12:45 PM
02-15-2007 12:48 PM
Check this for smartform to PDF
http://www.sap4.com/wiki/index.php/Genera_PDF_a_partir_de_Smartforms
Regards,
Santosh
02-15-2007 12:51 PM
02-15-2007 12:50 PM
Hello,
Please check this code and replace the variables as per ur reqt.
This is the code which is working perfectly .
* event handler for checking and processing user input and
* for defining navigation
DATA: cached_response TYPE REF TO if_http_response.
DATA: response TYPE REF TO if_http_response.
DATA: guid TYPE guid_32.
* generated result: PDF format
DATA: l_pdf_xstring TYPE xstring,
lt_lines TYPE TABLE OF tline,
ls_line TYPE tline,
l_pdf_len TYPE i.
DATA: lf_fm_name TYPE rs38l_fnam ,
e_ssfcrescl TYPE ssfcrescl,
lv_spool TYPE tsfspoolid,
e_ssfctrlop TYPE ssfctrlop,
e_ssfcompop TYPE ssfcompop.
DATA w_printer TYPE rspopname."user01-spld.
DATA:l_doc_output_info TYPE ssfcrespd, "#EC NEEDED
l_job_output_info TYPE ssfcrescl, "#EC NEEDED
l_job_output_options TYPE ssfcresop. "#EC NEEDED
DATA :l_devtype TYPE rspoptype.
* Get the function module name of Smartform
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = '/BSHP/FW_SF_LIST_DEL'
variant = ' '
direct_call = ' '
IMPORTING
fm_name = lf_fm_name "/1BCDWB/SF00000084
EXCEPTIONS
no_form = 1
no_function_module = 2
OTHERS = 3.
IF sy-subrc <> 0.
* MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
* WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
* Set print parameters
e_ssfctrlop-no_dialog = 'X' .
*-----------------------------------------------------------------------
* Setting of output options
*-----------------------------------------------------------------------
* language
language = sy-langu.
TRANSLATE language TO UPPER CASE.
e_ssfctrlop-langu = language.
* set control parameters to get the output format (OTF) from Smart Forms
e_ssfctrlop-no_dialog = 'X'.
e_ssfctrlop-getotf = 'X'.
* get device type from language
CALL FUNCTION 'SSF_GET_DEVICE_TYPE'
EXPORTING
i_language = language
* i_application = 'SAPDEFAULT'
IMPORTING
e_devtype = l_devtype
EXCEPTIONS
no_language = 1
language_not_installed = 2
no_devtype_found = 3
system_error = 4
OTHERS = 5.
IF sy-subrc <> 0.
* error handling
* MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
* WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
* set device type in output options
e_ssfcompop-tdprinter = l_devtype.
* Call the func module of the Smartform
CALL FUNCTION lf_fm_name " '/1BCDWB/SF00000084'
EXPORTING
control_parameters = e_ssfctrlop
output_options = e_ssfcompop
user_settings = space
* sf_werks = p_werks
sf_lifnr = p_lifnr
sf_matnr_low = s_matnr_low
sf_matnr_high = s_matnr_high
sf_vbeln_low = s_vbeln_low
sf_vbeln_high = s_vbeln_high
sf_lfdat_low = s_lfdat_low
sf_lfdat_high = s_lfdat_high
sf_vgbel_low = s_vgbel_low
sf_vgbel_high = s_vgbel_high
IMPORTING
document_output_info = l_doc_output_info
job_output_info = l_job_output_info
job_output_options = l_job_output_options
TABLES
gt_final_fi = gt_final
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 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.
*-----------------------------------------------------------------------
* Conversion of output format OTF into PDF format
*-----------------------------------------------------------------------
* now convert the final document (OTF format) into PDF format
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
* MAX_LINEWIDTH = 132
* ARCHIVE_INDEX = ' '
* COPYNUMBER = 0
IMPORTING
bin_filesize = l_pdf_len
bin_file = l_pdf_xstring " binary file
TABLES
otf = l_job_output_info-otfdata
lines = lt_lines
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
err_bad_otf = 4
OTHERS = 5 .
IF sy-subrc EQ 0.
CREATE OBJECT cached_response TYPE cl_http_response EXPORTING add_c_msg = 1.
l_pdf_len = XSTRLEN( l_pdf_xstring ).
cached_response->set_data( data = l_pdf_xstring
length = l_pdf_len ).
cached_response->set_header_field( name = if_http_header_fields=>content_type
value = 'application/pdf' ).
cached_response->set_status( code = 200 reason = 'OK' ).
cached_response->server_cache_expire_rel( expires_rel = 180 ).
CALL FUNCTION 'GUID_CREATE'
IMPORTING
ev_guid_32 = guid.
CONCATENATE runtime->application_url '/' guid '.pdf' INTO display_url.
cl_http_server=>server_cache_upload( url = display_url
response = cached_response ).
ENDIF.
U will get the url of the pdf in the display_url.
Please reward points if this is helpful.
Regards,
Deepu.k
Note: display_url type string,
language TYPE TDSPRAS.
Message was edited by:
deepu k
02-15-2007 12:53 PM
02-15-2007 12:53 PM
Hi,
Try the following code:
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
format = 'PDF'
max_linewidth = 134
IMPORTING
bin_filesize = v_size
TABLES
otf = x_output_data-otfdata
lines = it_lines
EXCEPTIONS
err_max_linewidth = 1
err_format = 2
err_conv_not_possible = 3
OTHERS = 4.
CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'
EXPORTING
line_width_dst = 255
TABLES
content_in = it_lines
content_out = it_soli
EXCEPTIONS
err_line_width_src_too_long = 1
err_line_width_dst_too_long = 2
err_conv_failed = 3
OTHERS = 4.
CALL FUNCTION 'ZFUNC_CONVERT_DATA_ODC01'
EXPORTING
iv_byte_mode = 'X'
TABLES
it_data = it_lines
et_data = it_table.
*-----To caluculate total number of lines of internal table
DESCRIBE TABLE it_table LINES v_lines.
*-----Function module to download the output file.
CALL FUNCTION 'DOWNLOAD'
EXPORTING
bin_filesize = v_size
filename = ' '
filetype = 'BIN'
IMPORTING
act_filename = v_filename
TABLES
data_tab = it_lines.
Reward points if helful asnwer.
Ashvender
02-15-2007 12:53 PM