*&---------------------------------------------------------------------*
*& Report ZPDF_TO_SPOOL.
*&
*&---------------------------------------------------------------------*
report ZPDF_TO_SPOOL.
*&---------------------------------------------------------------------*
*& Declarations
*&---------------------------------------------------------------------*
data : w_options like itcpo ,
it_otfdata type standard table of itcoo ,
it_tlines type standard table of tline ,
bin_filesize type i ,
bin_file type xstring ,
printer like tsp01-rqdest value 'LP01',
append type c value 'X',
doctype type adsdoctype value 'ADSP' ,
adstype type string,
l_strlen type i,
l_strlen1 type i,
nopdf type c value '',
globaldir(100),
pathname(256),
myfile type string,
handle like sy-tabix,
spoolid like tsp01-rqident,
partname type adspart,
filename type file_name,
pages type i,
size type i.
data: begin of datatab occurs 100,
line(80) type x,
end of datatab.
*&---------------------------------------------------------------------*
*& Start of selection
*&---------------------------------------------------------------------*
start-of-selection.
w_options-tdgetotf = 'X'.
w_options-tddest = 'LP01'.
*--Call the Script
call function 'OPEN_FORM'
exporting
device = 'PRINTER'
dialog = ' '
form = 'ZTEST'
language = sy-langu
options = w_options.
call function 'WRITE_FORM'
exporting
* element = '520'
function = 'SET'
type = 'BODY'
window = 'MAIN'.
call function 'CLOSE_FORM'
tables
otfdata = it_otfdata.
*--Convert from OTF to PDF format
* bin_file needs to be XSTRING format.
call function 'CONVERT_OTF'
exporting
format = 'PDF'
max_linewidth = 255
importing
bin_filesize = bin_filesize
bin_file = bin_file
tables
otf = it_otfdata
lines = it_tlines.
call function 'ADS_SR_OPEN'
exporting
dest = printer
append = append
doctype = doctype
importing
handle = handle
spoolid = spoolid
partname = partname
exceptions
device_missing = 1
no_such_device = 2
operation_failed = 3
wrong_doctype = 4
others = 5.
* l_strlen = STRLEN( bin_file ).
* l_strlen1 = STRLEN( bin_file ).
l_strlen = bin_filesize .
l_strlen1 = bin_filesize .
do.
if l_strlen gt 80.
move bin_file+0(80) to datatab-line.
append datatab.
l_strlen = l_strlen - 80.
bin_file = bin_file+80.
else.
move bin_file+0(l_strlen) to datatab-line.
append datatab.
exit.
endif.
enddo.
* Filename from partname
concatenate partname '.pdf' into filename.
* Get path of global directory
call 'C_SAPGPARAM'
id 'NAME' field 'DIR_GLOBAL'
id 'VALUE' field globaldir.
* Create fully qualified path
concatenate globaldir '/' filename into pathname.
myfile = pathname.
open dataset myfile for output in binary mode.
if sy-subrc = 0.
loop at datatab.
transfer datatab to myfile.
endloop.
close dataset myfile.
endif.
size = l_strlen1.
pages = 1.
call function 'ADS_SR_CONFIRM'
exporting
handle = handle
partname = partname
size = size
pages = pages
no_pdf = nopdf
exceptions
handle_not_valid = 1
operation_failed = 2
others = 3.
call function 'ADS_SR_CLOSE'
exporting
handle = handle
exceptions
handle_not_valid = 1
operation_failed = 2
others = 3.
end-of-selection.
No comments:
Post a Comment