2014 Jun 11 7:30 AM
Hi All,
I have used this FM's 'CONVERT_OTF_2_PDF' for multiple pdf generation in loop. First pdf is generating fine. From the second pdf file making a problem.
Second pdf file is getting generated but I couldn't open it. It showing a error message as 'There was an error in opening this doc. The file is damaged'.
Thanks
Govendran Gopi
2014 Jun 11 7:40 AM
Hi Govendran,
did you clear and refresh your internal tables and variables before each FM call? I came across several FMs that don't initialize an internal table before using and filling it.
Maybe that's worth a try. If this FM also doesn't initialize the fields, it will add the new generated PDF data to the old table and then you might get a damaged file when you try to open it.
Cheers,
Marc
2014 Jun 11 7:40 AM
Hi Govendran,
did you clear and refresh your internal tables and variables before each FM call? I came across several FMs that don't initialize an internal table before using and filling it.
Maybe that's worth a try. If this FM also doesn't initialize the fields, it will add the new generated PDF data to the old table and then you might get a damaged file when you try to open it.
Cheers,
Marc
2014 Jun 11 7:52 AM
Hi Marc,
I have already cleared all the fileds and internal tables on each iteration of the loop. But the probelm still exist.
2014 Jun 11 7:53 AM
Hi Govendran,
could you post your loop including the FM call and what you do with the pdf table after the call?
Do you store them on the server?
Instead of using CONVERT_OTF_2_PDF, try to use the "general" OTF conversion FM "CONVERT_OTF". I use it like this in a WebDynpro Scenario without problems:
CALL FUNCTION 'CONVERT_OTF'
EXPORTING
FORMAT = 'PDF'
* ARCHIVE_INDEX = archive_index
PDF_DELETE_OTFTAB = 'X'
IMPORTING
BIN_FILESIZE = lv_pdf_size
BIN_FILE = pdf
TABLES
otf = otfdata
lines = otflines
EXCEPTIONS
ERR_MAX_LINEWIDTH = 1
ERR_FORMAT = 2
ERR_CONV_NOT_POSSIBLE = 3
ERR_BAD_OTF = 4
OTHERS = 5
.
2014 Jun 11 8:16 AM
Yeah I wil store them in application server.
LOOP AT lt_xx INTO ls_xx.
CLEAR : ls_otf_form ,
lv_bin_filesize ,
lt_otf_data[] ,
lt_docs[] ,
lt_pdf[] .
ls_ssfctrlop-no_dialog = 'X'.
ls_ssfctrlop-getotf = 'X'.
* ls_ssfctrlop-no_open = 'X'.
* ls_ssfctrlop-no_close = 'X'.
CALL FUNCTION lv_func_name
EXPORTING
control_parameters = ls_ssfctrlop
output_options = ls_output_options
user_settings = ''
IMPORTING
job_output_info = ls_otf_form
TABLES
gt_xx = lt_xx
gt_yy = lt_yy
EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.
IF sy-subrc EQ 0.
* Copying the otf data to the internal table
lt_otf_data = ls_otf_form-otfdata[].
ENDIF.
*Converting OTF to PDF format
CALL FUNCTION 'CONVERT_OTF_2_PDF'
IMPORTING
bin_filesize = lv_bin_filesize
TABLES
otf = lt_otf_data
doctab_archive = lt_docs
lines = lt_pdf
EXCEPTIONS
err_conv_not_possible = 1
err_otf_mc_noendmarker = 2
OTHERS = 3.
*Converting the lt_pdf data to xstring
IF NOT lt_pdf IS INITIAL.
LOOP AT lt_pdf INTO ls_pdf.
ASSIGN ls_pdf TO <fs_x> CASTING TYPE x.
CONCATENATE lv_pdf <fs_x> INTO lv_pdf IN BYTE MODE.
ENDLOOP.
ENDIF.
lv_filename = 'path'.
OPEN DATASET lv_filename FOR OUTPUT IN BINARY MODE.
IF sy-subrc EQ 0.
lv_pdf = lv_pdf+0(lv_bin_filesize).
TRANSFER lv_pdf TO lv_filename.
CLOSE DATASET lv_filename.
ENDIF.
ENDLOOP.
2014 Jun 11 8:25 AM
Well, looks good so far. I think this should work.
Try using the FM CONVERT_OTF as it returns the binary file for you, so you won't need to cast data here and can transfer the returned file.
Maybe it works this way. Casting could be a problem, I'm currently not quite sure about this. Had trouble sometimes because of different encodings and binary interpretations between systems.
Marc
2014 Jun 11 8:26 AM
I have tried this FM CALL FUNCTION 'CONVERT_OTF' but it doesn't works
2014 Jun 11 9:02 AM
Hi,
Try using FM 'CONVERT_OTF_2_PDF' after your main loop on table lt_xx.
First append all smartform OTF Output in a single OTF internal Table.
Append first OTF output as it is into table lt_otf_data and from Second OTF Output onwards tillyour last call to smartform, remove the line from ls_otf_form-otfdata where tdprintcom = '//'.
Now, calculate the TABIX of lt_otf_data till tdprintcom = 'EP' , and append ls_otf_form-otfdata to lt_otf_data from this TABIX onwards.
Repeat this process for each smartform call.
Now, after main loop, your internal table LT_OTF_DATA will have OTF data for all smartforms.
pass this to FM 'CONVERT_OTF_2_PDF' outside the main loop.
Let me know if you need any other info.
Thanks
Bhavika
2014 Jun 11 9:23 AM
Hi Govendran,
just wrote a small report that uses your FM. I read two differen spool jobs and get the OTF data, then I use your approach. Have a look at this, especially at the end, as I don't do any conversion from my pdf lines table. It worked without any problem. I created two different pdfs inside my do-loop on the application server, downloaded them via transaction CG3Y and could open both without any problem:
REPORT Z_PDF_TEST.
DATA BEGIN OF otf OCCURS 1000.
INCLUDE STRUCTURE itcoo.
DATA END OF otf.
DATA: request LIKE TSP01-RQIDENT,
path(14) TYPE C.
DATA: bin_filesize TYPE i.
DATA: doctab type STANDARD TABLE OF docs,
pdf type STANDARD TABLE OF tline,
wa_pdf LIKE LINE OF pdf.
DO 2 TIMES.
CLEAR: otf[].
IF sy-index EQ 1.
request = '6217'.
path = '/tmp/test1.pdf'.
ELSEIF sy-index EQ 2.
request = '6219'.
path = '/tmp/test2.pdf'.
ENDIF.
CALL FUNCTION 'RSPO_RETURN_SPOOLJOB'
EXPORTING
rqident = request
* FIRST_LINE = 1
* LAST_LINE = LAST_LINE
DESIRED_TYPE = 'OTF'
* IMPORTING
* REAL_TYPE = REAL_TYPE
* SP_LANG = SP_LANG
TABLES
buffer = otf
* BUFFER_PDF = BUFFER_PDF
* EXCEPTIONS
* NO_SUCH_JOB = 1
* JOB_CONTAINS_NO_DATA = 2
* SELECTION_EMPTY = 3
* NO_PERMISSION = 4
* CAN_NOT_ACCESS = 5
* READ_ERROR = 6
* TYPE_NO_MATCH = 7
* OTHERS = 8
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION 'CONVERT_OTF_2_PDF'
* EXPORTING
* USE_OTF_MC_CMD = 'X'
* ARCHIVE_INDEX = ARCHIVE_INDEX
IMPORTING
BIN_FILESIZE = BIN_FILESIZE
TABLES
otf = otf
doctab_archive = doctab
lines = pdf
* EXCEPTIONS
* ERR_CONV_NOT_POSSIBLE = 1
* ERR_OTF_MC_NOENDMARKER = 2
* OTHERS = 3
.
OPEN DATASET path FOR OUTPUT IN BINARY MODE.
LOOP AT pdf INTO wa_pdf.
TRANSFER wa_pdf TO path.
ENDLOOP.
CLOSE DATASET path.
ENDDO.
2014 Jun 11 10:30 AM
Dear Marc,
Its works fine now. I have removed the casting. It is the cause for the problem. Thanks.
2014 Jun 11 10:21 AM