Skip to Content
0
Former Member
Apr 06, 2011 at 07:20 PM

Merge Different Spools containing a Single PDF page into a Single PDF file.

152 Views

Greetings,

I am developing a custom object where in i need to read PDF file from many different Spools(Range given on Input Screen), where each spool has a single PDF page in it. I need to combine all these PDF Pages into a single PDF file & either create a new Spool or save it on an Application Server.

At present i have developed the code where in i am able to read the PDF files from different spools & convert them into Binary but i am not able to generate it back to PDF file.

Kindly find my code for your reference.

CODE:-

START-OF-SELECTION.

PERFORM f_get_spool_1000 .

PERFORM g_conv_pdf_to_bin_2000 .

----


&----


*& Form F_GET_SPOOL_1000

&----


  • text

----


FORM f_get_spool_1000 .

SELECT * FROM tsp01

INTO TABLE gt_tsp01

WHERE rqident IN s_spool

ORDER BY rqcretime DESCENDING.

IF sy-subrc = 0.

SORT gt_tsp01 BY rqident .

ENDIF.

ENDFORM.

&----


*& Form G_CONV_PDF_TO_OTF_2000

&----


  • text

----


DATA: lv_filename_out TYPE string,

lv_len TYPE i,

lt_tab TYPE tsfixml .

DATA: lwa_print_parms LIKE pri_params,

lv_valid(1) TYPE c .

DATA: lv_linsz LIKE sy-linsz VALUE 132, " Line size

lv_paart LIKE sy-paart VALUE 'X_65_132'. " Paper Format

DATA : lt_tsp01 TYPE STANDARD TABLE OF tsp01 ,

lwa_tsp01 TYPE tsp01 .

CLEAR : gv_pdf, gwa_tsp01, gv_renderpagecount .

LOOP AT gt_tsp01 INTO gwa_tsp01.

CALL FUNCTION 'FPCOMP_CREATE_PDF_FROM_SPOOL'

EXPORTING

i_spoolid = gwa_tsp01-rqident

i_partnum = 1

IMPORTING

e_pdf = gv_pdf

e_renderpagecount = gv_renderpagecount

e_pdf_file = gv_pdf_file

EXCEPTIONS

ads_error = 1

usage_error = 2

system_error = 3

internal_error = 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.

CLEAR lv_len .

REFRESH gt_bin .

CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'

EXPORTING

buffer = gv_pdf

IMPORTING

output_length = lv_len

TABLES

binary_tab = gt_bin.

CLEAR gwa_bin .

LOOP AT gt_bin INTO gwa_bin.

APPEND gwa_bin TO gt_listout.

CLEAR gwa_bin .

ENDLOOP.

ENDLOOP.

  • Get FP reference

DATA: lo_fp TYPE REF TO if_fp VALUE IS INITIAL,

lo_pdfobj TYPE REF TO if_fp_pdf_object VALUE IS INITIAL,

lo_exc TYPE REF TO cx_root,

lv_xslt_message TYPE string .

lo_fp = cl_fp=>get_reference( ).

  • For handling exceptions

DATA: lo_fpex TYPE REF TO cx_fp_runtime VALUE IS INITIAL.

TRY.

lo_pdfobj = lo_fp->create_pdf_object( connection = 'ADS' ).

  • Set document

lo_pdfobj->set_document(

EXPORTING

pdfdata = gt_listout ).

  • Tell PDF object to extract data

lo_pdfobj->set_extractdata( ).

  • Execute the call to ADS

lo_pdfobj->execute( ).

CATCH cx_root INTO lo_exc.

lv_xslt_message = lo_exc->get_text( ).

ENDTRY.

Your quick reply would be of great help.

Regards.