07-09-2018 7:58 AM
Hello Experts,
I want to accept XML file from user and convert it directly into PDF and let it downloaded to local system.
Is there any way I can do it.
I have tried below code but PDF file is getting corrupt...
CALL METHOD gs_cl_xml->import_from_file
EXPORTING
filename = p_file
RECEIVING
retcode = gv_subrc.
IF gv_subrc = 0.
CALL METHOD gs_cl_xml->render_2_xstring
IMPORTING
retcode = gv_subrc
stream = gv_xml_string
size = gv_size.
IF gv_subrc = 0.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = gv_xml_string
TABLES
binary_tab = lt_data.
cl_gui_frontend_services=>gui_download(
exporting
filename = 'C:\Users\ast07367\Desktop\PDF.pdf'
filetype = 'BIN'
changing
data_tab = LT_DATA ).
Endif.
Endif.
07-09-2018 8:19 AM
SCMS_XSTRING_TO_BINARY function has exporting parameter OUTPUT_LENGTH, which is important value which you should use in GUI_DOWNLOAD. If you do not use it, 'BIN' gui_download does not know the correct size of the created file.
But anyway, I am not sure if you can simply save binary XML and call it PDF. But that is another thing.
07-09-2018 8:20 AM
In future please use the "code" button on the editor to post code examples. Use right click "post as text" when pasting code from an editor, and after posting, ensure the code is nicely formatted and readable.
I've done it for you this time.
07-10-2018 6:22 AM
You cant directly convert from XML to PDF, they are difference thing. You can convert data from XML to internal table, write it to spool then export spool to PDF. See this wiki ( you can replace WRITE statement with fm: RSPO_WRITE_SPOOLREQUEST in order to write data to spool ) .
plus, see this report to know more about spool to pdf: RSTXPDFT4.