PDF görüntüleme (lokal)
Uygulama sunucusundan dosyayı yerel geçici klasöre indirme ve istemci tarafında PDF dosyasını görüntüleme örneğidir.
constants gc_directory type afilename value `/tmp`.
PERFORM view_pdf using gc_directory `Kilavuz.pdf` .
form view_pdf using prm_directory type afilename
prm_tcode type tcode .
data: prm_filename type afilename.
concatenate prm_tcode `.pdf` into prm_filename.
constants blocksize type i value 524287.
constants packagesize type i value 8.
types ty_datablock(blocksize) type x.
data lv_package_len type i.
data lv_subrc type sy-subrc.
data lv_block_len type i.
data: lv_full_path type string.
data lv_msgv1 like sy-msgv1.
data lv_filesize type p.
data ls_data type ty_datablock.
data lt_data type standard table of ty_datablock.
data: lv_eps_filename type epsfilnam,
lv_eps_dirname type epsdirnam,
lv_dosya_adi_varsayilan type string,
lv_file_downloaded type c.
lv_eps_dirname = prm_directory .
lv_eps_filename = prm_filename .
concatenate prm_directory `/` prm_filename into lv_full_path.
call function `EPS_GET_FILE_ATTRIBUTES`
exporting
file_name = lv_eps_filename
dir_name = lv_eps_dirname
importing
file_size_long = lv_filesize
exceptions
read_directory_failed
read_attributes_failed.
"Open the file on application server
open dataset lv_full_path for input in binary mode message lv_msgv1.
if sy-subrc <> 0.
message e048(cms) with lv_full_path lv_msgv1 raising file_read_error.
exit.
endif.
do.
refresh lt_data.
lv_package_len = 0.
do packagesize times.
clear ls_data.
clear lv_block_len.
read dataset lv_full_path into ls_data maximum length blocksize length lv_block_len.
lv_subrc = sy-subrc.
if lv_block_len > 0.
lv_package_len = lv_package_len + lv_block_len.
append ls_data to lt_data.
endif.
"End of file
if lv_subrc <> 0.
exit.
endif.
enddo.
if lv_package_len > 0.
data: lv_str_filename type string.
data: lv_str_path type string.
data: lv_str_fullpath type string.
lv_dosya_adi_varsayilan = prm_filename.
data: lv_temp_directory type string .
data: lv_separator type C .
* cl_gui_cfw=>flush( ).
call method cl_gui_frontend_services=>get_temp_directory
changing
temp_dir = lv_temp_directory " Temporary Directory
exceptions
cntl_error = 1
error_no_gui = 2
not_supported_by_gui = 3
others = 4.
call method cl_gui_frontend_services=>get_file_separator
changing
FILE_SEPARATOR = lv_separator
EXCEPTIONS
CNTL_ERROR = 1
ERROR_NO_GUI = 2
NOT_SUPPORTED_BY_GUI = 3.
call method cl_gui_cfw=>flush
exceptions
cntl_system_error = 1
cntl_error = 2
others = 3.
CONCATENATE lv_temp_directory lv_separator lv_dosya_adi_varsayilan into lv_str_fullpath.
CALL FUNCTION `GUI_DOWNLOAD`
EXPORTING
bin_filesize = lv_package_len
filename = lv_str_fullpath
filetype = `BIN`
append = `` "lv_append
show_transfer_status = abap_false
CONFIRM_OVERWRITE = ` `
TABLES
data_tab = lt_data
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.
if sy-subrc eq 0.
lv_file_downloaded = `X`.
endif.
endif.
"End of file
if lv_subrc <> 0.
exit.
endif.
enddo.
"Close the file on application server
close dataset lv_full_path.
if lv_str_fullpath is not INITIAL and lv_file_downloaded = `X`.
CALL METHOD cl_gui_frontend_services=>execute
EXPORTING
document = lv_str_fullpath
EXCEPTIONS
OTHERS = 1.
endif.
endform. "#view_pdf